From: Tomas Doran Date: Mon, 29 Jun 2009 23:17:47 +0000 (+0000) Subject: Don't mangle query parameters passed to uri_for, the list X-Git-Tag: 5.80007~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=1f851263ba70ba7d398ed19b45eaaca482f5aaa3 Don't mangle query parameters passed to uri_for, the list --- diff --git a/Changes b/Changes index a89dd99..c2000fd 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ # This file documents the revision history for Perl extension Catalyst. + Bug fixes: + - Don't mangle query parameters passed to uri_for + - Tests for this (t0m + Byron Young + Amir Sadoughi) + 5.80006 2009-06-29 23:37:47 Bug fixes: diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 27a232c..25ebecf 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1232,12 +1232,12 @@ sub uri_for { my $key = $_; $val = '' unless defined $val; (map { - $_ = "$_"; - utf8::encode( $_ ) if utf8::is_utf8($_); + my $param = "$_"; + utf8::encode( $param ) if utf8::is_utf8($param); # using the URI::Escape pattern here so utf8 chars survive - s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go; - s/ /+/g; - "${key}=$_"; } ( ref $val eq 'ARRAY' ? @$val : $val )); + $param =~ s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go; + $param =~ s/ /+/g; + "${key}=$param"; } ( ref $val eq 'ARRAY' ? @$val : $val )); } @keys); } diff --git a/t/unit_core_uri_for.t b/t/unit_core_uri_for.t index af47c9f..3dd3a69 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 => 19; +use Test::More tests => 20; use URI; use_ok('Catalyst'); @@ -133,3 +133,13 @@ TODO: { ); } +# make sure caller's query parameter hash isn't messed up +{ + my $query_params_base = {test => "one two", + bar => ["foo baz", "bar"]}; + my $query_params_test = {test => "one two", + bar => ["foo baz", "bar"]}; + Catalyst::uri_for($context, '/bar/baz', $query_params_test); + is_deeply($query_params_base, $query_params_test, + "uri_for() doesn't mess up query parameter hash in the caller"); +}