Don't mangle query parameters passed to uri_for, the list
Tomas Doran [Mon, 29 Jun 2009 23:17:47 +0000 (23:17 +0000)]
Changes
lib/Catalyst.pm
t/unit_core_uri_for.t

diff --git a/Changes b/Changes
index a89dd99..c2000fd 100644 (file)
--- 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:
index 27a232c..25ebecf 100644 (file)
@@ -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);
     }
 
index af47c9f..3dd3a69 100644 (file)
@@ -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");
+}