Browse Source

Bug 28316: escape brackets in the search query

This patch screens square and curly brackets which have no special
language meaning.

To reproduce:
1) using ES, search for the book with title that contains
square and/or curly brackets, like "book [second edition]", which will
result in error.
2) apply the patch.
3) search for that book again, ensure that it works now.

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
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>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.11.x
Petro Vashchuk 3 years ago
committed by Jonathan Druart
parent
commit
fa39f9a65e
  1. 3
      Koha/SearchEngine/Elasticsearch/QueryBuilder.pm

3
Koha/SearchEngine/Elasticsearch/QueryBuilder.pm

@ -930,7 +930,6 @@ sub _clean_search_term {
$term =~ s/=/:/g;
$term = $self->_convert_index_strings_freeform($term);
$term =~ s/[{}]/"/g;
# Remove unbalanced quotes
my $unquoted = $term;
@ -952,6 +951,8 @@ sub _clean_search_term {
# and correctly ignore unevenly backslashed:
$term =~ s/((?<!\\)(?:[\\]{2})*:[^:\s]+(?<!\\)(?:[\\]{2})*)(?=:)/$1\\/g;
# screen all brackets with backslash
$term =~ s/(?<!\\)(?:[\\]{2})*([\{\}\[\]])$lookahead/\\$1/g;
return $term;
}

Loading…
Cancel
Save