Bugzilla – Attachment 124710 Details for
Bug 28316
Fix ES crashes related to various punctuation characters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28316: screen unquoted semicolons and all followup colons
Bug-28316-screen-unquoted-semicolons-and-all-follo.patch (text/plain), 2.53 KB, created by
Martin Renvoize
on 2021-09-09 13:02:59 UTC
(
hide
)
Description:
Bug 28316: screen unquoted semicolons and all followup colons
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2021-09-09 13:02:59 UTC
Size:
2.53 KB
patch
obsolete
>From 2964c34711acdd7560f73b2d2f4602dcefd9481c Mon Sep 17 00:00:00 2001 >From: Petro Vashchuk <stalkernoid@gmail.com> >Date: Fri, 18 Jun 2021 10:43:14 +0300 >Subject: [PATCH] Bug 28316: screen unquoted semicolons and all followup colons > >Currently searches like: "book:", ":book" and "host-item:test:n" >cause internal server errors. > >This patch adds additional regexes that remove the colons at the start >and end of the query, and another regex that screens all follow-up >colons that go after the first colon to avoid errors when searching for >"host-item:test:n". > >To reproduce: >1) using ES, search for the book with title that contains >semicolon at the start or at the end of the line, separated with spaces, >this should cause internal server error. >2) try doing the same with something like "host-item:test:n", it should >result in error as well. >3) apply the patch. >4) repeat steps 1-2, ensure that it works now. > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > .../SearchEngine/Elasticsearch/QueryBuilder.pm | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index ab292b1379..091fa56366 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -938,14 +938,20 @@ sub _clean_search_term { > if ($count % 2 == 1) { > $term = $unquoted; > } >- >- # Remove unquoted colons that have whitespace on either side of them >- $term =~ s/(:+)(\s+)$lookahead/$2/g; >- $term =~ s/(\s+)(:+)$lookahead/$1/g; >- $term =~ s/^://; >- > $term = $self->_query_regex_escape_process($term); > >+ # remove leading and trailing colons mixed with optional slashes and spaces >+ $term =~ s/^([\s\\]*:\s*)+//; >+ $term =~ s/([\s\\]*:\s*)+$//; >+ # remove unquoted colons that have whitespace on either side of them >+ $term =~ s/([\s\\]*:\s*)+(\s+)$lookahead/$2/g; >+ $term =~ s/(\s+)([\s\\]*:\s*)+$lookahead/$1/g; >+ # replace with spaces all repeated colons no matter how they surrounded with spaces and slashes >+ $term =~ s/([\s\\]*:\s*){2,}$lookahead/ /g; >+ # screen all followups for colons after first colon, >+ # and correctly ignore unevenly backslashed: >+ $term =~ s/((?<!\\)(?:[\\]{2})*:[^:\s]+(?<!\\)(?:[\\]{2})*)(?=:)/$1\\/g; >+ > return $term; > } > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28316
:
121435
|
121443
|
121561
|
121562
|
121751
|
121752
|
121753
|
121754
|
121755
|
121756
|
121837
|
121838
|
121839
|
121840
|
121841
|
121842
|
121975
|
121976
|
121977
|
121978
|
121979
|
121980
|
122103
|
122104
|
122105
|
122106
|
122107
|
122108
|
122201
|
122202
|
122203
|
122204
|
122205
|
122206
|
122801
|
122802
|
122803
|
122804
|
122805
|
122806
|
123601
|
123602
|
123603
|
123604
|
123605
|
123606
|
124372
|
124373
|
124374
|
124375
|
124376
|
124377
|
124378
|
124560
|
124561
|
124562
|
124563
|
124564
|
124565
|
124566
|
124709
| 124710 |
124711
|
124712
|
124713
|
124714
|
124715