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>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit 59c26ce5f3)
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
This commit is contained in:
parent
c8f5c155f3
commit
1bfda79f26
|
|
@ -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@~~RE$rgx_i~~@x
|
||||
) {
|
||||
@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/~~RE$i~~/$saved_regexes[$i]/;
|
||||
}
|
||||
return $term;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue