remove 0-length query string components so warnings aren't thrown (RT #36428)
Brian Cassidy [Tue, 24 Jun 2008 00:14:21 +0000 (00:14 +0000)]
Changes
lib/Catalyst/Engine.pm
t/live_engine_request_parameters.t

diff --git a/Changes b/Changes
index 5160891..014f7c6 100644 (file)
--- 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)
index 424d661..b7b8be0 100644 (file)
@@ -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 ) {
         
index 81c9ba9..060bc9e 100644 (file)
@@ -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' );
+}