Bugzilla – Attachment 122107 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: avoid messing up regexes in the search queries
Bug-28316-avoid-messing-up-regexes-in-the-search-q.patch (text/plain), 2.22 KB, created by
Peter Vashchuk
on 2021-06-18 07:49:26 UTC
(
hide
)
Description:
Bug 28316: avoid messing up regexes in the search queries
Filename:
MIME Type:
Creator:
Peter Vashchuk
Created:
2021-06-18 07:49:26 UTC
Size:
2.22 KB
patch
obsolete
>From 362e6bb92ea5cc2256180be37a4bb9d39c1422e8 Mon Sep 17 00:00:00 2001 >From: Petro Vashchuk <stalkernoid@gmail.com> >Date: Fri, 18 Jun 2021 10:01:18 +0300 >Subject: [PATCH] Bug 28316: avoid messing up regexes in the search queries > >This patch ensures that the behavior with >QueryRegexEscapeOptions set to values other than >"Escape" still will works as expected. > >It does so by storing the contents of regexes >before escaping special characters and >then restores the contents of regexes back to how >it was before, ensuring that searching with regex is possible. >--- > Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 3bc982f796..a91ca289e7 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -939,6 +939,15 @@ 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~~") >+ $term =~ s/(?<!\\)((?:[\\]{2})*)(\{|\[)([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+(?<!\\)(?:[\\]{2})*)(\}|\])/$1.'~~L'.($2 eq '[' ? 'S':'C').'~~'.$3.'~~R'.($4 eq ']' ? 'S':'C').'~~'/ge; >+ } > # save all regex contents away before escaping brackets: > my @saved_regexes; > my $rgx_i = 0; >@@ -974,6 +983,10 @@ sub _clean_search_term { > for (my $i = 0; $i < @saved_regexes; $i++) { > $term =~ s/~~XI$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.31.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