Bugzilla – Attachment 124714 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: escape ES ranges if QueryAutoTruncate is enabled
Bug-28316-escape-ES-ranges-if-QueryAutoTruncate-is.patch (text/plain), 2.92 KB, created by
Martin Renvoize
on 2021-09-09 13:03:22 UTC
(
hide
)
Description:
Bug 28316: escape ES ranges if QueryAutoTruncate is enabled
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2021-09-09 13:03:22 UTC
Size:
2.92 KB
patch
obsolete
>From 1c2155c73b89d50a128ce1e3060c57b0f618bcdb Mon Sep 17 00:00:00 2001 >From: Petro Vashchuk <stalkernoid@gmail.com> >Date: Mon, 6 Sep 2021 16:46:45 +0300 >Subject: [PATCH] Bug 28316: escape ES ranges if QueryAutoTruncate is enabled > >if QueryAutoTruncate enabled we will have any special operators ruined >for example: "test [6 TO 7]" will be converted to "test* [6* TO* 7]" >so no reason to keep ranges when QueryAutoTruncate set to "enabled" > >1) enable QueryAutoTruncate at your sysprefs. >2) perform a search using range, for example: "[1999 TO 2020]", >it shouldn't work the way it's supposed to. >3) apply the patch. >4) perform the same search with range, ensure that it works correctly. > >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> >--- > .../Elasticsearch/QueryBuilder.pm | 25 +++++++++++++++++++ > 1 file changed, 25 insertions(+) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 50eb26516f..580acc221f 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -939,7 +939,28 @@ sub _clean_search_term { > } > $term = $self->_query_regex_escape_process($term); > >+ # because of _truncate_terms and if QueryAutoTruncate enabled >+ # we will have any special operators ruined by _truncate_terms: >+ # for ex. search for "test [6 TO 7]" will be converted to "test* [6* TO* 7]" >+ # so no reason to keep ranges in QueryAutoTruncate==true case: >+ my $truncate = C4::Context->preference("QueryAutoTruncate") || 0; >+ unless($truncate) { >+ # replace all ranges with any square/curly brackets combinations to temporary substitutions (ex: "{a TO b]"" -> "~~LC~~a TO b~~RS~~") >+ # (where L is for left and C is for Curly and so on) >+ $term =~ s/ >+ (?<!\\) >+ (?<backslashes>(?:[\\]{2})*) >+ (?<leftbracket>\{|\[) >+ (?<ranges> >+ [^\s\[\]\{\}]+\ TO\ [^\s\[\]\{\}]+ >+ (?<!\\) >+ (?:[\\]{2})* >+ ) >+ (?<rightbracket>\}|\]) >+ /$+{backslashes}.'~~L'.($+{leftbracket} eq '[' ? 'S':'C').'~~'.$+{ranges}.'~~R'.($+{rightbracket} eq ']' ? 'S':'C').'~~'/gex; >+ } > # save all regex contents away before escaping brackets: >+ # (same trick as with brackets above, just RE for 'RegularExpression') > my @saved_regexes; > my $rgx_i = 0; > while( >@@ -974,6 +995,10 @@ sub _clean_search_term { > for (my $i = 0; $i < @saved_regexes; $i++) { > $term =~ s/~~RE$i~~/$saved_regexes[$i]/; > } >+ unless($truncate) { >+ # restore temporary weird substitutions back to normal brackets >+ $term =~ s/~~L(C|S)~~([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+)~~R(C|S)~~/($1 eq 'S' ? '[':'{').$2.($3 eq 'S' ? ']':'}')/ge; >+ } > 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