Make sure '?' are encoded in path parts for uri_for
Ash Berlin [Wed, 15 Nov 2006 00:37:52 +0000 (00:37 +0000)]
lib/Catalyst.pm
t/unit_core_uri_for.t

index 367b742..8028afa 100644 (file)
@@ -920,6 +920,7 @@ sub uri_for {
     $path ||= '';
     $namespace = '' if $path =~ /^\//;
     $path =~ s/^\///;
+    $path =~ s/\?/%3F/g;
 
     my $params =
       ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
@@ -933,7 +934,7 @@ sub uri_for {
     };
     
     # join args with '/', or a blank string
-    my $args = ( scalar @args ? '/' . join( '/', @args ) : '' );
+    my $args = ( scalar @args ? '/' . join( '/', map {s/\?/%3F/g; $_} @args ) : '' );
     $args =~ s/^\/// unless $path;
     my $res =
       URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ), $base )
index 72ccda1..612d0b0 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 11;
+use Test::More tests => 13;
 use URI;
 
 use_ok('Catalyst');
@@ -43,6 +43,15 @@ is(
     'URI for undef action with query params'
 );
 
+is (Catalyst::uri_for( $context, '/bar/wibble?' )->as_string,
+   'http://127.0.0.1/foo/bar/wibble%3F', 'Question Mark gets encoded'
+);
+   
+is( Catalyst::uri_for( $context, qw/bar wibble?/, 'with space' )->as_string,
+    'http://127.0.0.1/foo/yada/bar/wibble%3F/with%20space', 'Space gets encoded'
+);
+
+
 # test with utf-8
 is(
     Catalyst::uri_for( $context, 'quux', { param1 => "\x{2620}" } )->as_string,