From ab43a3208c08c0853e4848d57937536b4824a927 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Fri, 11 Jun 2021 16:13:58 +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 screens 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. --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index a39931ab0b..49bb1a8109 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -939,12 +939,17 @@ sub _clean_search_term { $term = $unquoted; } + $term = $self->_query_regex_escape_process($term); + # Remove unquoted colons that have whitespace on either side of them + $term =~ s/^((?_query_regex_escape_process($term); + # screen all followups for colons after first colon, + # and correctly ignore unevenly backslashed: + $term =~ s/((?