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.
This commit is contained in:
Colin Kuskie 2007-12-16 04:13:53 +00:00
parent cda571c3ef
commit b70ef9d23a
2 changed files with 11 additions and 4 deletions

View file

@ -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

View file

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