From b70ef9d23a061372887b23edd2a90eb0d413f92e Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 16 Dec 2007 04:13:53 +0000 Subject: [PATCH] Add tests to cover the removal of extensions in the "directory" parts of the path. Refactor out the while loop with match and nested s/// into a single regexp. --- lib/WebGUI/Asset.pm | 7 ++++--- t/Asset/Asset.t | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 7d29ce9bd..6a10a56ce 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -583,9 +583,10 @@ sub fixUrl { } # remove multiple extensions from the url if there are some - while ($url =~ m{^(.*)\.\w+(/.*)$}) { - $url =~ s{^(.*)\.\w+(/.*)$}{$1$2}ig; - } + $url =~ s{ + (\.\w+)* # Strip off any number of extensions + (?=/) # Followed by a slash + }{}xg; # And delete all of them in the string # add automatic extension if we're supposed to if ($self->session->setting->get("urlExtension") ne "" #don't add an extension if one isn't set diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index a18724547..614b370c9 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -17,7 +17,7 @@ use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Wobject::Navigation; -use Test::More tests => 37; # increment this value for each test you create +use Test::More tests => 40; # increment this value for each test you create use Test::MockObject; my $session = WebGUI::Test->session; @@ -170,6 +170,12 @@ is($importNode->fixUrl('/extras1'), '_extras1', 'trailing underscore in extrasUR $session->config->set('extrasURL', 'http://mysite.com/extras2'); is($importNode->fixUrl('/extras2'), '_extras2', 'underscore prepended to URLs that match the extrasURL, even with http://'); +##Now, check extension removal + +is($importNode->fixUrl('one.html/two.html'), 'one/two.html', 'extensions are not allowed higher up in the path'); +is($importNode->fixUrl('one.html/two.html/three.html'), 'one/two/three.html', 'extensions are not allowed anywhere in the path'); +is($importNode->fixUrl('one.one.html/two.html/three.html'), 'one/two/three.html', 'multiple dot extensions are removed in any path element'); + $session->setting->set('urlExtension', 'html'); END: {