From 0406e8254646828287b6adda84305aa7692650b7 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 27 Sep 2010 09:29:07 -0700 Subject: [PATCH] Links in wiki search to add a missing page should encode the titles to make them URL safe. Fixes bug #11883. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/WikiMaster.pm | 3 +- t/Asset/Wobject/WikiMaster/search.t | 67 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 t/Asset/Wobject/WikiMaster/search.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index e845f49db..028139c8b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,6 +1,7 @@ 7.10.2 - fixed #11884: Editing Templates impossible / Code editor not loaded - recommitted ukplayer. Removal broke Matrix. Licencing information was available but overlooked. + - fixed #11883: Wiki "Add page" link does not encode special chars 7.10.1 - fixed #11851: Story Topic: top story variables should be available all the time diff --git a/lib/WebGUI/Asset/Wobject/WikiMaster.pm b/lib/WebGUI/Asset/Wobject/WikiMaster.pm index 50c35273b..b60a94534 100644 --- a/lib/WebGUI/Asset/Wobject/WikiMaster.pm +++ b/lib/WebGUI/Asset/Wobject/WikiMaster.pm @@ -23,6 +23,7 @@ use WebGUI::Utility; use HTML::Parser; use URI::Escape; use WebGUI::Form; +use WebGUI::Search; use Clone qw/clone/; #------------------------------------------------------------------- @@ -985,7 +986,7 @@ sub www_search { mostPopularUrl=>$self->getUrl("func=mostPopular"), mostPopularLabel=>$i18n->get("mostPopularLabel"), wikiHomeUrl=>$self->getUrl, - addPageUrl=>$self->getUrl("func=add;class=WebGUI::Asset::WikiPage;title=".$queryString), + addPageUrl=>$self->getUrl("func=add;class=WebGUI::Asset::WikiPage;title=".$self->session->url->escape($queryString)), }; $self->appendSearchBoxVars($var, $queryString); if (length $queryString) { diff --git a/t/Asset/Wobject/WikiMaster/search.t b/t/Asset/Wobject/WikiMaster/search.t new file mode 100644 index 000000000..0b97c9709 --- /dev/null +++ b/t/Asset/Wobject/WikiMaster/search.t @@ -0,0 +1,67 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +# Test the featured page of the Wiki +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../../lib"; +use Test::More; +use Test::Deep; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; +my $import = WebGUI::Asset->getImportNode( $session ); + +my $templateId = 'WIKIMASTER_TEMPLATE___'; + +my $templateMock = Test::MockObject->new({}); +$templateMock->set_isa('WebGUI::Asset::Template'); +$templateMock->set_always('getId', $templateId); +my $templateVars; +$templateMock->mock('process', sub { $templateVars = $_[1]; } ); + +my $wiki + = $import->addChild( { + className => 'WebGUI::Asset::Wobject::WikiMaster', + searchTemplateId => $templateId, + } ); + +WebGUI::Test->addToCleanup($wiki); + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 1; # Increment this number for each test you create + +$session->request->setup_body({ + query => 'Red&Andy', +}); + +{ + WebGUI::Test->mockAssetId($templateId, $templateMock); + $wiki->www_search(); + WebGUI::Test->unmockAssetId($templateId); +} + +is $templateVars->{addPageUrl}, + $wiki->getUrl('func=add;class=WebGUI::Asset::WikiPage;title=Red%26Andy'), + 'search encodes unsafe characters in addPageUrl'; + +#---------------------------------------------------------------------------- +# + +#vim:ft=perl