Skip to content

Commit

Permalink
Item13777: Backport the URL and Search encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Oct 2, 2015
1 parent ac03713 commit 4c9a985
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -2845,7 +2845,7 @@ sub verify_Search_expression {
$this->{test_topicObject}->expandMacros(
'%SEARCH{"TestForm.Ecks~\'Bl>ah*\'" type="query" nototal="on"}%');
my $expected = <<'HERE';
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>TestForm.Ecks~'Bl&gt;ah*'</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>TestForm.Ecks~&#39;Bl&#62;ah&#42;&#39;</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
HERE

$this->assert_str_equals( $expected, $actual );
Expand All @@ -2854,7 +2854,7 @@ HERE
$this->{test_topicObject}->expandMacros(
'%SEARCH{"TestForm.Ecks = \'B/lah*\'" type="query" nototal="on"}%');
$expected = <<'HERE';
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>TestForm.Ecks = 'B/lah*'</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>TestForm.Ecks &#61; &#39;B/lah&#42;&#39;</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
HERE
$this->assert_str_equals( $expected, $actual );

Expand Down
41 changes: 21 additions & 20 deletions core/data/System/WebSearch.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1309486560" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1443745119" format="1.1" version="1"}%
%META:TOPICPARENT{name="WebHome"}%
%IF{
"$'URLPARAM{tab}'='search' OR $'URLPARAM{tab}'='' AND NOT $TAB='advanced'"
Expand Down Expand Up @@ -41,7 +41,7 @@
<input type='hidden' name='tab' value='%URLPARAM{"tab" default="search"}%' />
<div class='foswikiFormSteps'>
<div class='foswikiFormStep'>
<input type='text' class='foswikiInputField foswikiFocus' name='search' value='%URLPARAM{"search" encode="entity"}%' size='40' style='width:99%' />
<input type='text' class='foswikiInputField foswikiFocus' name='search' value='%URLPARAM{"search" encode="entity"}%' size='40' style='width:99%' placeholder='%MAKETEXT{"Search"}%' />
</div>
<div class='foswikiFormStep'>
%TWISTY{
Expand Down Expand Up @@ -237,25 +237,26 @@

%STARTSECTION{"searchresults"}%%IF{
"$'URLPARAM{search}'!=''"
then="<h2>Search results</h2>
then="<h2>%MAKETEXT{"Search results"}%</h2>
$percentINCLUDE{$quot%SYSTEMWEB%.%TOPIC%$quot section=$quotsearchfeed$quot}$percent"
}%%SEARCH{
"%URLPARAM{"search" encode="quote"}%"
"%URLPARAM{"search" encode="entities, quote"}%" decode="entities"
type="%URLPARAM{"type" default="word"}%"
scope="%URLPARAM{"scope" encode="quote"}%"
web="%URLPARAM{"web" encode="quote"}%"%IF{
scope="%URLPARAM{"scope" encode="safe, quote"}%"
web="%URLPARAM{"web" encode="safe, quote"}%"%IF{
"{EnableHierarchicalWebs}"
then="recurse=\"%URLPARAM{"recurse" encode="quote"}%\""
then="recurse=\"%URLPARAM{"recurse" encode="safe, quote"}%\""
}%
excludetopic="%URLPARAM{"excludetopic" encode="quote"}%"
nosearch="%URLPARAM{"nosearch" encode="quote"}%"
casesensitive="%URLPARAM{"casesensitive" encode="quote"}%"
nosummary="%URLPARAM{"nosummary" encode="quote"}%"
nototal="%URLPARAM{"nototal" encode="quote"}%"
order="%URLPARAM{"order" encode="quote"}%"
reverse="%URLPARAM{"reverse" encode="quote"}%"
topic="%URLPARAM{"searchtopic" encode="safe, quote"}%"
excludetopic="%URLPARAM{"excludetopic" encode="safe, quote"}%"
nosearch="%URLPARAM{"nosearch" encode="safe, quote"}%"
casesensitive="%URLPARAM{"casesensitive" encode="safe, quote"}%"
nosummary="%URLPARAM{"nosummary" encode="safe, quote"}%"
nototal="%URLPARAM{"nototal" encode="safe, quote"}%"
order="%URLPARAM{"order" encode="safe, quote"}%"
reverse="%URLPARAM{"reverse" encode="safe, quote"}%"
pager="on"
limit="%URLPARAM{"limit" encode="quote" default="%DEFAULTPAGESIZE%"}%"
limit="%URLPARAM{"limit" encode="safe, quote" default="%DEFAULTPAGESIZE%"}%"
pagesize="%DEFAULTPAGESIZE%"
zeroresults="%IF{
"defined search and $search!=''"
Expand All @@ -272,7 +273,7 @@ $percentINCLUDE{$quot%SYSTEMWEB%.%TOPIC%$quot section=$quotsearchfeed$quot}$perc
"'%URLPARAM{"regex"}%'='on' OR '%URLPARAM{"type"}%'='regex'"
then="regex"
else="word"
}%;excludetopic=%URLPARAM{"excludetopic" encode="url" default="%TOPIC%,WebHome,%STATISTICSTOPIC%"}%;web=%URLPARAM{"web" encode="url" default="%BASEWEB%"}%;recurse=%URLPARAM{"recurse" encode="url"}%;limit=%URLPARAM{"limit" encode="url" default="all"}%;scope=%URLPARAM{"scope" encode="url" default="text"}%;casesensitive=%URLPARAM{"casesensitive" encode="url" default="off"}%'>%MAKETEXT{"Get notified on changes on this search"}%</a>%ENDSECTION{"searchfeedlink"}%
}%;excludetopic=%URLPARAM{"excludetopic" encode="url" default="%TOPIC%,%HOMETOPIC%,%STATISTICSTOPIC%"}%;web=%URLPARAM{"web" encode="url" default="%BASEWEB%"}%;recurse=%URLPARAM{"recurse" encode="url"}%;limit=%URLPARAM{"limit" encode="url" default="all"}%;scope=%URLPARAM{"scope" encode="url" default="text"}%;casesensitive=%URLPARAM{"casesensitive" encode="url" default="off"}%'>%MAKETEXT{"Get notified on changes on this search"}%</a>%ENDSECTION{"searchfeedlink"}%


%STARTSECTION{"querysearchexample"}%%IF{
Expand All @@ -285,14 +286,14 @@ $percentINCLUDE{$quot%SYSTEMWEB%.%TOPIC%$quot section=$quotsearchfeed$quot}$perc
%MAKETEXT{"To display the above search results in a topic, copy-paste the following markup:"}%
<pre class='tml'>
%<nop>SEARCH{
"%URLPARAM{"search" encode="quote"}%"
"%URLPARAM{"search" encode="entities, quote"}%"
type="%URLPARAM{"type" default="%SEARCHDEFAULTTTYPE%"}%"%FORMAT{
"scope,web,recurse,nosearch,casesensitive,nosummary,nototal,order,reverse,limit,search"
"scope,web,recurse,nosearch,casesensitive,nosummary,nototal,order,reverse,limit"
type="string"
header="$n"
format="$percntIF{
\"(defined $item AND $'$item') AND ('$item' != 'recurse' OR {EnableHierarchicalWebs})\"
then=\" $item=\\"$percntURLPARAM{\"$item\" encode=\"quote\"}$percnt\\"$n\"
then=\" $item=\\"$percntURLPARAM{\"$item\" encode=\"safe, quote\"}$percnt\\"$n\"
}$percnt"
separator=""
}%}%
Expand All @@ -302,7 +303,7 @@ $percentINCLUDE{$quot%SYSTEMWEB%.%TOPIC%$quot section=$quotsearchfeed$quot}$perc

%STARTSECTION{"searchbyletterlink"}%%IF{
"$'URLPARAM{searchletter}'='%letter%'"
then="%letter%"
then="<strong>%letter%</strong>"
else="<a href='%SCRIPTURLPATH{"search"}%/%BASEWEB%/%TOPIC%?scope=topic&amp;type=regex&amp;search=%5E%letter%;$percentINCLUDE{$quot%TOPIC%$quot section=$quotsearchparamsadvanced$quot}$percent;searchletter=%letter%;tab=az'>%letter%</a>"
}%%ENDSECTION{"searchbyletterlink"}%

Expand Down
4 changes: 2 additions & 2 deletions core/data/TestCases/TestCaseAutoFormattedSearchDetails.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="BaseUserMapping_333" date="1246078286" format="1.1" version="1.1"}%
%META:TOPICINFO{author="ProjectContributor" date="1443744445" format="1.1" version="1"}%
%META:TOPICPARENT{name="WebHome"}%
---+!! %TOPIC%
Description: Automated formatted search tests verifying refactor of format= functionality in foswiki 1.1
Expand All @@ -11,7 +11,7 @@ The major risk is the default formatting where web's are separated - for paging
---++ default search formatting - 1 expand rex old Tmwiki default multi-weboutput 4 webs
---+++ Expected
<!-- expected 1 expand rex old Tmwiki default multi-weboutput 4 webs -->
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>(WebPreferences|WebTopicList|WebHome)$</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>(WebPreferences&#124;WebTopicList&#124;WebHome)$</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>

<h4 class="foswikiSearchResultsHeader" style="border-color:yellow"><b>Results from TestCases web</b> retrieved at @TIME (@REX(GMT|Local)</h4>
<div class="foswikiSearchResult"><div class="foswikiTopRow">
Expand Down
9 changes: 3 additions & 6 deletions core/lib/Foswiki/Search.pm
Expand Up @@ -428,13 +428,10 @@ sub searchWeb {
# Ommit any text before search results if either nosearch or nonoise is on
my $nonoise = Foswiki::isTrue( $params{nonoise} );
my $noSearch = Foswiki::isTrue( $params{nosearch}, $nonoise );
unless ($noSearch) {
my $searchStr = $searchString;
$searchStr =~ s/&/&amp;/go;
$searchStr =~ s/</&lt;/go;
$searchStr =~ s/>/&gt;/go;

$tmplSearch =~ s/%SEARCHSTRING%/$searchStr/go;
unless ($noSearch) {
my $searchStr = Foswiki::entityEncode($searchString);
$tmplSearch =~ s/%SEARCHSTRING%/$searchStr/g;
&$callback( $cbdata, $tmplSearch );
}

Expand Down

0 comments on commit 4c9a985

Please sign in to comment.