From: Ash Berlin Date: Wed, 15 Nov 2006 00:37:52 +0000 (+0000) Subject: Make sure '?' are encoded in path parts for uri_for X-Git-Tag: 5.7099_04~270 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=57e74a1e0e82d0f06e56b58a50f84007af4c4798 Make sure '?' are encoded in path parts for uri_for --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 367b742..8028afa 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -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 ) diff --git a/t/unit_core_uri_for.t b/t/unit_core_uri_for.t index 72ccda1..612d0b0 100644 --- a/t/unit_core_uri_for.t +++ b/t/unit_core_uri_for.t @@ -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,