Dropped URI::Query, put back old query code, moved query param code into Engine
Andy Grundman [Wed, 12 Oct 2005 14:11:35 +0000 (14:11 +0000)]
Changes
lib/Catalyst/Engine.pm
lib/Catalyst/Engine/CGI.pm
t/live/engine/request/uri.t

diff --git a/Changes b/Changes
index afa85dd..e158336 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Tis file documents the revision history for Perl extension Catalyst.
 
 5.50
+        - Fixed handling of escaped query strings.
         - Added upload parameters back into $c->req->params.
         - Added multiple paths support to dispatcher
         - Fixed bug in req->path where changing the path added a trailing
index ecd6834..b5cba7b 100644 (file)
@@ -7,6 +7,7 @@ use Data::Dumper;
 use HTML::Entities;
 use HTTP::Body;
 use HTTP::Headers;
+use URI::QueryParam;
 
 # input position and length
 __PACKAGE__->mk_accessors(qw/read_position read_length/);
@@ -333,7 +334,19 @@ sub prepare_path { }
 
 =cut
 
-sub prepare_query_parameters { }
+sub prepare_query_parameters {
+    my ( $self, $c, $query_string ) = @_;
+
+    # replace semi-colons
+    $query_string =~ s/;/&/g;
+
+    my $u = URI->new( '', 'http' );
+        $u->query( $query_string );
+        for my $key ( $u->query_param ) {
+        my @vals = $u->query_param($key);  
+        $c->request->query_parameters->{$key} = @vals > 1 ? [@vals] : $vals[0];  
+    }
+}
 
 =item $self->prepare_read($c)
 
index 847209f..6fb71b9 100644 (file)
@@ -4,7 +4,6 @@ use strict;
 use base 'Catalyst::Engine';
 use NEXT;
 use URI;
-use URI::Query;
 
 =head1 NAME
 
@@ -156,9 +155,8 @@ sub prepare_path {
 
 sub prepare_query_parameters {
     my ( $self, $c ) = @_;
-
-    my $u = URI::Query->new( $ENV{QUERY_STRING} );
-    $c->request->query_parameters( { $u->hash } );
+    
+    $self->SUPER::prepare_query_parameters( $c, $ENV{QUERY_STRING} );
 }
 
 =item $self->prepare_write($c)
index 8d91502..b0a2f0a 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use FindBin;\r
 use lib "$FindBin::Bin/../../lib";\r
 \r
-use Test::More tests => 18;\r
+use Test::More tests => 23;\r
 use Catalyst::Test 'TestApp';\r
 use Catalyst::Request;\r
 \r
@@ -49,4 +49,13 @@ my $creq;
     ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );\r
     is( $creq->{uri}->query, 'a=1;a=2;b=3', 'Query string ok' );\r
     is_deeply( $creq->{parameters}, $parameters, 'Parameters ok' );\r
-}    \r
+}\r
+\r
+# test that query params are unescaped properly\r
+{\r
+    ok( my $response = request('http://localhost/engine/request/uri?text=Catalyst%20Rocks'), 'Request' );\r
+    ok( $response->is_success, 'Response Successful 2xx' );\r
+    ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );\r
+    is( $creq->{uri}->query, 'text=Catalyst%20Rocks', 'Query string ok' );\r
+    is( $creq->{parameters}->{text}, 'Catalyst Rocks', 'Unescaped param ok' );\r
+}\r