Bugzilla – Attachment 124376 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), 1.99 KB, created by
Martin Renvoize (ashimema)
on 2021-09-01 15:01:14 UTC
(
hide
)
Description:
Bug 28316: avoid messing up regexes in the search queries
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-09-01 15:01:14 UTC
Size:
1.99 KB
patch
obsolete
>From 2e91f035d9a6a802faaddef22aef4efe191ba8cd Mon Sep 17 00:00:00 2001 >From: Petro Vashchuk <stalkernoid@gmail.com> >Date: Mon, 14 Jun 2021 16:38:51 +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. > >Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > .../SearchEngine/Elasticsearch/QueryBuilder.pm | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index b1d22f2bd9..57ce0086a9 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -939,6 +939,19 @@ sub _clean_search_term { > } > $term = $self->_query_regex_escape_process($term); > >+ # save all regex contents away before escaping brackets: >+ my @saved_regexes; >+ my $rgx_i = 0; >+ while( >+ $term =~ s@( >+ (?<!\\)(?:[\\]{2})*/ >+ (?:[^/]+|(?<=\\)(?:[\\]{2})*/)+ >+ (?<!\\)(?:[\\]{2})*/ >+ )$lookahead@"~~XI$rgx_i~~"@ex >+ ) { >+ @saved_regexes[$rgx_i++] = $1; >+ } >+ > # remove leading and trailing colons mixed with optional slashes and spaces > $term =~ s/^([\s\\]*:\s*)+//; > $term =~ s/([\s\\]*:\s*)+$//; >@@ -956,6 +969,11 @@ sub _clean_search_term { > > # screen all brackets with backslash > $term =~ s/(?<!\\)(?:[\\]{2})*([\{\}\[\]])$lookahead/\\$1/g; >+ >+ # restore all regex contents after escaping brackets: >+ for (my $i = 0; $i < @saved_regexes; $i++) { >+ $term =~ s/~~XI$i~~/$saved_regexes[$i]/; >+ } > 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