• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item7834: Sanitation of search

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Engine Search Normal Closed   patch 6.1.0

Edit Form Data

Summary:
Reported By:
Codebase:
Applies To:
Component:
Priority:
Current State:
Waiting For:
Target Release:
Released In:
 

Detail

-- TWiki:Main/PeterThoeny - 2018-01-01

Related/prerequisite to fix this is TWiki:Codev.NewModeSearchEncodingInENCODEandURLPARAM (Item7847)

-- TWiki:Main.PeterThoeny - 2018-07-14

Patch core code:

Index: lib/TWiki/Search.pm
===================================================================
--- lib/TWiki/Search.pm   (revision 30573)
+++ lib/TWiki/Search.pm   (working copy)
@@ -533,6 +533,7 @@
     my $output = '';
     my $tmpl   = '';
 
+    $searchString =~ s/$TWiki::percentSubstitute/%/go; # Item7847
     my $originalSearch = $searchString;
     my $spacedTopic;
 
Index: lib/TWiki.pm
===================================================================
--- lib/TWiki.pm   (revision 30573)
+++ lib/TWiki.pm   (working copy)
@@ -93,6 +93,7 @@
 # Other computed constants
 use vars qw(
       $TranslationToken
+      $percentSubstitute
       $twikiLibDir
       %regex
       %functionTags
@@ -120,6 +121,12 @@
 # See Codev.NationalCharTokenClash for more.
 $TranslationToken= "\0";
 
+# Hack to substitute a % into a non-printable character so that a
+# search string can be passed from URLPARAM to SEARCH without variable
+# expansion, e.g. for a literal search.
+# (TWiki:Codev.NewModeSearchEncodingInENCODEandURLPARAM & Item7847)
+$percentSubstitute = "\x1a";
+
 =pod
 
 ---++ StaticMethod getTWikiLibDir() -> $path
@@ -4675,9 +4682,14 @@
         # entity encode, encode also space, newline and linefeed
         return entityEncode( $text, " \n\r" );
     } elsif ( $type =~ /^quotes?$/i ) {
-        # escape quotes with backslash (Bugs:Item3383 fix)
+        # escape quotes with backslash (Item3383)
         $text =~ s/\"/\\"/go;
         return $text;
+    } elsif ( $type =~ /^search$/i ) {
+        # substitue % with \x1a (Item7847), also escape quotes with backslash
+        $text =~ s/\"/\\"/go;
+        $text =~ s/%/$percentSubstitute/go;
+        return $text;
     } elsif ($type =~ /^url$/i) {
         # legacy
         $text =~ s/\r*\n\r*/<br \/>/g;

Patch TWiki topics:

Index: data/TWiki/WebSearch.txt
===================================================================
--- data/TWiki/WebSearch.txt   (revision 30573)
+++ data/TWiki/WebSearch.txt   (working copy)
@@ -1,4 +1,4 @@
-%META:TOPICINFO{author="TWikiContributor" date="1431720932" format="1.1" version="$Rev$"}%
+%META:TOPICINFO{author="TWikiContributor" date="1531611774" format="1.1" version="$Rev$"}%
 %META:TOPICPARENT{name="WebHome"}%
 ---+ %MAKETEXT{"Search in [_1] Web" args="<nop>%BASEWEB%"}%
 
@@ -6,7 +6,7 @@
 
 %INCLUDE{"%SYSTEMWEB%.SearchResultsPagination" section="preamble"}%<nop>
 %SEARCH{ 
-"%URLPARAM{"search" encode="quote"}%" 
+"%URLPARAM{"search" encode="search"}%" 
 type="%URLPARAM{"type" encode="entity" default="%SEARCHDEFAULTTYPE%"}%" 
 scope="%URLPARAM{"scope" encode="entity"}%" 
 web="%URLPARAM{"web" encode="entity"}%" 
Index: data/TWiki/WebSearchAdvanced.txt
===================================================================
--- data/TWiki/WebSearchAdvanced.txt   (revision 30573)
+++ data/TWiki/WebSearchAdvanced.txt   (working copy)
@@ -1,4 +1,4 @@
-%META:TOPICINFO{author="TWikiContributor" date="1431652587" format="1.1" version="$Rev$"}%
+%META:TOPICINFO{author="TWikiContributor" date="1531611770" format="1.1" version="$Rev$"}%
 %META:TOPICPARENT{name="WebSearch"}%
 ---+ %MAKETEXT{"Advanced Search"}%
 
@@ -6,7 +6,7 @@
 
 %INCLUDE{"%SYSTEMWEB%.SearchResultsPagination" section="preamble"}%<nop>
 %SEARCH{
- "%URLPARAM{"search" encode="quote"}%"
+ "%URLPARAM{"search" encode="search"}%"
  type="%IF{" '%URLPARAM{"regex" encode="entity"}%' = 'on' or '%URLPARAM{"type" encode="entity"}%' = 'regex'" the
n="regex" else="%SEARCHDEFAULTTYPE%"}%"
  scope="%URLPARAM{"scope" encode="entity"}%"
  web="%URLPARAM{"web" encode="entity"}%"

-- TWiki:Main.PeterThoeny - 2018-07-15

ItemTemplate
Summary Sanitation of search
ReportedBy TWiki:Main.PeterThoeny
Codebase ~twiki4, 6.0.2
SVN Range TWiki-6.0.2-trunk, Fri, 03 Nov 2017, build 30403
AppliesTo Engine
Component Search
Priority Normal
CurrentState Closed
WaitingFor

Checkins TWikirev:30577 TWikirev:30578 TWikirev:30579 TWikirev:30580 TWikirev:30581
TargetRelease patch
ReleasedIn 6.1.0
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r9 - 2018-07-17 - PeterThoeny
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback