From: Brian Cassidy Date: Tue, 24 Jun 2008 00:14:21 +0000 (+0000) Subject: remove 0-length query string components so warnings aren't thrown (RT #36428) X-Git-Tag: 5.7099_04~60^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e9cc26fe8e0cdd2c91b11c2cf251cce33852729;hp=3c40261066f0ade558228d68c7f59cb329d6b0fb;p=catagits%2FCatalyst-Runtime.git remove 0-length query string components so warnings aren't thrown (RT #36428) --- diff --git a/Changes b/Changes index 5160891..014f7c6 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ # This file documents the revision history for Perl extension Catalyst. 5.7xxx xxx + - remove 0-length query string components so warnings aren't thrown (RT #36428) - Update HTTP::Body dep so that the uploadtmp config value will work (RT #22540) - Fix for LocalRegex when used in the Root controller - Get some of the optional_* tests working from dirs with spaces (RT #26455) diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 424d661..b7b8be0 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -452,7 +452,7 @@ sub prepare_query_parameters { # replace semi-colons $query_string =~ s/;/&/g; - my @params = split /&/, $query_string; + my @params = grep { length $_ } split /&/, $query_string; for my $item ( @params ) { diff --git a/t/live_engine_request_parameters.t b/t/live_engine_request_parameters.t index 81c9ba9..060bc9e 100644 --- a/t/live_engine_request_parameters.t +++ b/t/live_engine_request_parameters.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 40; +use Test::More tests => 53; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -137,3 +137,26 @@ use HTTP::Request::Common; ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); is( $creq->{uri}->query, 'x=1&y=1&z=1', 'Catalyst::Request GET query_string' ); } + +{ + my $creq; + ok( my $response = request("http://localhost/dump/request?&&q="), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + ok( eval '$creq = ' . $response->content ); + is( keys %{$creq->{parameters}}, 1, 'remove empty parameter' ); + is( $creq->{parameters}->{q}, '', 'empty parameter' ); +} + +{ + my $creq; + ok( my $response = request("http://localhost/dump/request?&0&q="), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + ok( eval '$creq = ' . $response->content ); + is( keys %{$creq->{parameters}}, 2, 'remove empty parameter' ); + is( $creq->{parameters}->{q}, '', 'empty parameter' ); + ok( !defined $creq->{parameters}->{0}, 'empty parameter' ); +}