From 883e3d3095839a5c6f4825eb664242546ae38be4 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk 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 Signed-off-by: Martin Renvoize Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall (cherry picked from commit 59c26ce5f35f3f18830090b048d0cd6c2a1eb6fc) Signed-off-by: Victor Grousset/tuxayo --- .../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 d1a6065e7d..d6f28ac38f 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@( + (?