Skip to content

Commit

Permalink
Item15218: fix request parser and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Oct 4, 2023
1 parent cdc7781 commit 2e25bfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 9 additions & 8 deletions UnitTestContrib/test/unit/RequestTests.pm
Expand Up @@ -139,7 +139,7 @@ sub test_Request_parse {
my @paths = my @comparisons = (

#Query Path Params, Web topic, invalidWeb, invalidTopic
[ '/', undef, '', undef, undef, undef ],
[ '/', undef, undef, undef, undef, undef ],
[ '/', { topic => 'Main.WebHome' }, 'Main', 'WebHome', undef, undef ],

# topic= overrides any pathinfo
Expand All @@ -152,7 +152,7 @@ sub test_Request_parse {
# defaultweb is not processed by the request object, so web is unset by the Request.
[
'/', { defaultweb => 'Sandbox', topic => 'WebHome' },
'', 'WebHome', undef, undef
undef, 'WebHome', undef, undef
],

[ '/Main/WebHome', undef, 'Main', 'WebHome', undef, undef ],
Expand All @@ -168,8 +168,8 @@ sub test_Request_parse {
'/Web.Subweb.Webhome/', undef, 'Web/Subweb/Webhome', undef,
undef, undef
],
[ '/3#/blah', undef, undef, undef, '3#', undef ],
[ '/Web.a<script>lah', undef, undef, undef, undef, 'a<script>lah' ],
[ '/3#/blah', undef, undef, 'Blah', '3#', undef ],
[ '/Web.a<script>lah', undef, 'Web', undef, undef, 'a<script>lah' ],

# This next one works because of auto fix-up of lower case topic name
[ '/Blah/asdf', undef, 'Blah', 'Asdf', undef, undef ],
Expand All @@ -187,10 +187,11 @@ sub test_Request_parse {
$req->pathInfo( $set->[0] );
$this->createNewFoswikiSession( 'AdminUser', $req );

#print STDERR $req->pathInfo() . " web "
# . ( ( defined $req->web() ) ? $req->web() : 'undef' )
# . " topic "
# . ( ( defined $req->topic() ) ? $req->topic() : 'undef' ) . "\n";
#print STDERR "#$tn: "
# . $req->pathInfo()
# . " web=" . ($req->web() // 'undef')
# . " topic=" . ($req->topic() // 'undef')
# . "\n";

$this->assert_str_equals( $set->[0], $req->pathInfo,
"Test $tn: Wrong pathInfo value" );
Expand Down
14 changes: 8 additions & 6 deletions core/lib/Foswiki/Request.pm
Expand Up @@ -1092,6 +1092,7 @@ sub parse {

my $temptopic;
my @webs;
my $resp = {};

foreach (@parts) {
print STDERR "Checking $_\n" if TRACE;
Expand All @@ -1105,12 +1106,13 @@ sub parse {
# If we have evil, just report the invalid web or topic.
unless ($p) {

my $resp = {};
if ( $lastpart && !$trailingSlash ) {
$resp->{topic} = undef, $resp->{invalidTopic} = $_;
$resp->{topic} = undef;
$resp->{invalidTopic} = $_;
}
else {
$resp->{web} = undef, $resp->{invalidWeb} = $_;
$resp->{web} = undef;
$resp->{invalidWeb} = $_;
}
next;
}
Expand Down Expand Up @@ -1173,7 +1175,7 @@ sub parse {
$p = Foswiki::Sandbox::untaint( $_,
\&Foswiki::Sandbox::validateWebName );
unless ($p) {
my $resp = {
$resp = {
web => undef,
topic => undef,
invalidWeb => $_
Expand All @@ -1185,11 +1187,11 @@ sub parse {
}
}
}
my $resp = { web => join( '/', @webs ), topic => $temptopic };
$resp->{web} = join( '/', @webs ) if @webs;
$resp->{topic} = $temptopic;

#print STDERR Data::Dumper::Dumper( \$resp ) if TRACE;
return $resp;

}

1;
Expand Down

0 comments on commit 2e25bfe

Please sign in to comment.