From e7c87854def261efbe39057c98b8a1a5494bc320 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Tue, 22 Mar 2016 11:50:58 -0400 Subject: [PATCH] LP#1373601: Consider relevant characters before using word-boundary checks To perform unanchored phrase limits, we make sure that the phrase supplied by the user does not end in the middle of a word by bounding the condition with word-boundary bracket expresssions. However, if the phrase starts or ends with a non-word character (that is, something other than numbers, letters, or the underscore) then the word-boundary expression won't match. The effect of this is to cause phrase searches starting or ending in punctuation to fail when the user would not expect them to. To address this, we now test the phrase for word-iness at the front and back before applying word-boundary bracket expressions. Signed-off-by: Mike Rylander Signed-off-by: Kathy Lussier --- .../Application/Storage/Driver/Pg/QueryParser.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index f08b1e5428..ea557699a6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -85,15 +85,24 @@ sub quote_phrase_value { my $left_anchored = ''; my $right_anchored = ''; + my $left_wb = 0; + my $right_wb = 0; + $left_anchored = $1 if $value =~ m/^([*\^])/; $right_anchored = $1 if $value =~ m/([*\$])$/; + + # We can't use word-boundary bracket expressions if the relevant char + # is not actually a "word" characters. + $left_wb = $wb if $value =~ m/^\w+/; + $right_wb = $wb if $value =~ m/\w+$/; + $value =~ s/^[*\^]// if $left_anchored; $value =~ s/[*\$]$// if $right_anchored; $value = quotemeta($value); $value = '^' . $value if $left_anchored eq '^'; $value = "$value\$" if $right_anchored eq '$'; - $value = '[[:<:]]' . $value if $wb && !$left_anchored; - $value .= '[[:>:]]' if $wb && !$right_anchored; + $value = '[[:<:]]' . $value if $left_wb && !$left_anchored; + $value .= '[[:>:]]' if $right_wb && !$right_anchored; return $self->quote_value($value); } -- 2.43.2