From: Mike Rylander Date: Tue, 22 Mar 2016 15:50:58 +0000 (-0400) Subject: LP#1373601: Consider relevant characters before using word-boundary checks X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=de875779594720f9a405580c87e1d5754269e354;p=working%2FEvergreen.git 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 --- 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); }