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: {