Item14607: querysearch and multiple=on : uninitialized value $pattern in quotemeta

pencil
Priority: Normal
Current State: Confirmed
Released In: n/a
Target Release:
Applies To: Engine
Component: SEARCH
Branches:
Reported By: StefanH
Waiting For:
Last Change By: GeorgeClark
A query search with multiple=on leads to error messages (seen in httpd error_log):

%SEARCH{"1" scope="topic" topic="*" web="Main" type="query" multiple="on"}%

Messages seem to appear for every topic in the results:

Use of uninitialized value $pattern in quotemeta at .../wiki/lib/Foswiki/Search.pm line 835.

Regex searches do not have this problem.

-- StefanH - 22 Jan 2018

I have a possible fix for this.
diff --git a/core/lib/Foswiki/Search.pm b/core/lib/Foswiki/Search.pm
index 9818ca8..eb18569 100644
--- a/core/lib/Foswiki/Search.pm
+++ b/core/lib/Foswiki/Search.pm
@@ -831,18 +831,20 @@ sub formatResults {
                 #TODO: Sven wonders if this should be a HoistRE..
                 #TODO: well, um, and how does this work for query search?
                 my @tokens = @{ $query->tokens() };
-                my $pattern = $tokens[$#tokens];   # last token in an AND search
-                $pattern = quotemeta($pattern) if ( $type ne 'regex' );
-                $text = $info->{tom}->text() unless defined $text;
-                $text = '' unless defined $text;
-
-                if ($caseSensitive) {
-                    @multipleHitLines =
-                      reverse grep { /$pattern/ } split( /[\n\r]+/, $text );
-                }
-                else {
-                    @multipleHitLines =
-                      reverse grep { /$pattern/i } split( /[\n\r]+/, $text );
+                if ( @tokens ) {
+                    my $pattern = $tokens[$#tokens];   # last token in an AND search
+                    $pattern = quotemeta($pattern) if ( $type ne 'regex' );
+                    $text = $info->{tom}->text() unless defined $text;
+                    $text = '' unless defined $text;
+
+                    if ($caseSensitive) {
+                        @multipleHitLines =
+                          reverse grep { /$pattern/ } split( /[\n\r]+/, $text );
+                    }
+                    else {
+                        @multipleHitLines =
+                          reverse grep { /$pattern/i } split( /[\n\r]+/, $text );
+                    }
                 }
             }
 

-- GeorgeClark - 23 Jan 2018

Simpler patch without the white space changes:
diff --git a/core/lib/Foswiki/Search.pm b/core/lib/Foswiki/Search.pm
index 9818ca8..ede0d11 100644
--- a/core/lib/Foswiki/Search.pm
+++ b/core/lib/Foswiki/Search.pm
@@ -831,6 +831,7 @@ sub formatResults {
                 #TODO: Sven wonders if this should be a HoistRE..
                 #TODO: well, um, and how does this work for query search?
                 my @tokens = @{ $query->tokens() };
+                if ( @tokens ) {
                 my $pattern = $tokens[$#tokens];   # last token in an AND search
                 $pattern = quotemeta($pattern) if ( $type ne 'regex' );
                 $text = $info->{tom}->text() unless defined $text;
@@ -844,6 +845,7 @@ sub formatResults {
                     @multipleHitLines =
                       reverse grep { /$pattern/i } split( /[\n\r]+/, $text );
                 }
+                }
             }
 
             # Apply heading offset - posibly to each hit result independently

-- GeorgeClark - 23 Jan 2018

Thinking about it... multiple=on probably doesn't make much sense in a query search. So it should maybe just be removed in this case.

-- TestUser333 - 24 Jan 2018

The patch works for us and removes the errors. Thanks.

However, for a query search where condition = "Myformfield~'*foo*' OR Myformfield~'*bar*'", a topic with Myformfield='foobar' was not given twice in the results.

But this was just a quick test. In our case the parameter is not needed for query searches.

-- TestUser333 - 24 Jan 2018
 

ItemTemplate edit

Summary querysearch and multiple=on : uninitialized value $pattern in quotemeta
ReportedBy StefanH
Codebase 2.1.5, 2.1.4, trunk
SVN Range
AppliesTo Engine
Component SEARCH
Priority Normal
CurrentState Confirmed
WaitingFor
Checkins
ReleasedIn n/a
CheckinsOnBranches
trunkCheckins
masterCheckins
ItemBranchCheckins
Release02x01Checkins
Release02x00Checkins
Release01x01Checkins
Topic revision: r5 - 28 Mar 2018, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy