Documented a regexp in Session/Url.pm

Add passthruUrls to the list of URLs that are changed by fixUrl.
Wrote a bunch of POD for fixUrl
Changed the regular expressions related to badUrl so they don't need to copy the data.  This
will speed them up.
Fixed a bug where trailing slashes would defeat the badUrl check.
Re-indented according to WGBP.
Added tests to cover all of the changes.
This commit is contained in:
Colin Kuskie 2007-12-11 22:51:31 +00:00
parent c44a5a1bb6
commit afcc90b130
3 changed files with 71 additions and 19 deletions

View file

@ -17,7 +17,7 @@ use WebGUI::Session;
use WebGUI::Asset;
use WebGUI::Asset::Wobject::Navigation;
use Test::More tests => 32; # increment this value for each test you create
use Test::More tests => 39; # increment this value for each test you create
use Test::MockObject;
my $session = WebGUI::Test->session;
@ -147,4 +147,37 @@ $session->{_request} = $origRequest;
#
################################################################
is($importNode->fixUrl('1234'.'-'x250 . 'abcdefghijkl'), '1234'.'-'x216, 'fixUrl truncates to 220 characters');
is($importNode->fixUrl('1234'.'-'x235 . 'abcdefghij'), '1234'.'-'x235 . 'abcdefghij', 'fixUrl leaves long URLs under 250 characters alone');
is($importNode->fixUrl('1234'.'-'x250 . 'abcdefghij'), '1234'.'-'x216, 'fixUrl truncates long URLs over 250 characters to 220 characters');
my $origExtras = $session->config->get('extrasURL');
my $origUploads = $session->config->get('uploadsURL');
my $origPassthru = $session->config->get('passthruUrls');
$session->config->set('extrasURL', '/extras');
$session->config->set('uploadsURL', '/uploads');
$session->config->set('passthruUrls', [qw/pass1 pass2/]);
is($importNode->fixUrl('/extras'), '_extras', 'underscore prepended to URLs that match the extrasURL');
is($importNode->fixUrl('/uploads'), '_uploads', 'underscore prepended to URLs that match the uploadsURL');
is($importNode->fixUrl('/pass1'), '_pass1', 'underscore prepended to URLs that match any passthruUrl 1');
is($importNode->fixUrl('/pass2'), '_pass2', 'underscore prepended to URLs that match any passthruUrl 2');
#Now that we have verified that extrasURL and uploadsURL both work, just test one.
$session->config->set('extrasURL', '/extras1/');
is($importNode->fixUrl('/extras1'), '_extras1', 'trailing underscore in extrasURL does not defeat the check');
$session->config->set('extrasURL', 'http://mysite.com/extras2');
is($importNode->fixUrl('/extras2'), '_extras2', 'underscore prepended to URLs that match the extrasURL, even with http://');
END: {
$session->config->set('extrasURL', $origExtras);
$session->config->set('uploadsURL', $origUploads);
if (defined $origPassthru) {
$session->config->set('passthruUrls', $origPassthru);
}
else {
$session->config->delete('passthruUrls');
}
}