Item2508: No way to escape macros in a query search

pencil
Priority: Urgent
Current State: Closed
Released In: 1.1.0
Target Release: minor
Applies To: Engine
Component:
Branches:
Reported By: CrawfordCurrie
Waiting For:
Last Change By: KennethLavrsen
As observed in Support.Question354 there is no way to escape a character that participates in a macro for a query search.

There is a trivial fix - use \ as an escape character - but I'm concerned about the knock-on effects. Should I be?

Index: core/lib/Foswiki/Infix/Parser.pm
===================================================================
--- core/lib/Foswiki/Infix/Parser.pm   (revision 5795)
+++ core/lib/Foswiki/Infix/Parser.pm   (working copy)
@@ -217,6 +217,7 @@
             elsif ( $$input =~ s/^\s*(['"])(|.*?[^\\])\1// ) {
                 print STDERR "Tok: qs '$1'\n" if MONITOR_PARSER;
                 my $val = $2;
+                $val =~ s/(?<!\\)\\(.)/$1/g;
                 push( @opands,
                     $this->{client_class}
                       ->newLeaf( $val, $Foswiki::Infix::Node::STRING ) );
Index: UnitTestContrib/test/unit/QueryTests.pm
===================================================================
--- UnitTestContrib/test/unit/QueryTests.pm   (revision 5795)
+++ UnitTestContrib/test/unit/QueryTests.pm   (working copy)
@@ -74,6 +74,8 @@
         { name => "string", title => "String", value => "String" } );
     $meta->putKeyed( 'FIELD',
         { name => "boolean", title => "Boolean", value => "1" } );
+    $meta->putKeyed( 'FIELD',
+        { name => "macro", value => "%RED%" } );
 
     $meta->{_text} = "Green ideas sleep furiously";
 
@@ -113,6 +115,7 @@
     $this->check( "text",          "Green ideas sleep furiously" );
     $this->check( "string",        'String' );
     $this->check( "boolean",       1 );
+    $this->check( "macro",         '%RED%' );
 }
 
 sub test_meta_dot {
@@ -188,6 +191,9 @@
     $this->check( "string!='string'",             1 );
     $this->check( "string='string'",              0 );
     $this->check( "string~'string'",              0 );
+    $this->check( "macro='\%RED\%'",              1 );
+    $this->check( "macro~'\%RED?'",               1 );
+    $this->check( "macro~'?RED\%'",               1 );
 }
 
 sub test_num_uops {
-- CrawfordCurrie - 16 Dec 2009

FWIW, I've applied this patch to my server and, in addition to fixing the problem, I haven't (yet) noticed any adverse effects. Thanks!

-- BigBaaadBob - 17 Dec 2009

Committed to trunk.

-- CrawfordCurrie - 17 Dec 2009

ItemTemplate edit

Summary No way to escape macros in a query search
ReportedBy CrawfordCurrie
Codebase
SVN Range
AppliesTo Engine
Component
Priority Urgent
CurrentState Closed
WaitingFor
Checkins distro:65d43a333f6d
TargetRelease minor
ReleasedIn 1.1.0
Topic revision: r7 - 04 Oct 2010, KennethLavrsen
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