Fix typo
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 495a715..dd44d0f 100644 (file)
@@ -1265,6 +1265,9 @@ sub uri_for {
       ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
 
     carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
+    foreach my $arg (@args) {
+        utf8::encode($arg) if utf8::is_utf8($arg);
+    }
     s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
     if (blessed $path) { # Action object only.
         s|/|%2F|g for @args;
@@ -1293,17 +1296,6 @@ sub uri_for {
 
     undef($path) if (defined $path && $path eq '');
 
-    my $params =
-      ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
-
-    carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
-
-    foreach my $arg (@args) {
-        utf8::encode($arg) if utf8::is_utf8($arg);
-    }
-    s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
-    s|/|%2F| for @args;
-
     unshift(@args, $path);
 
     unless (defined $path && $path =~ s!^/!!) { # in-place strip
@@ -1335,6 +1327,7 @@ sub uri_for {
           (map {
               my $param = "$_";
               utf8::encode( $param ) if utf8::is_utf8($param);
+              # using the URI::Escape pattern here so utf8 chars survive
               $param =~ s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go;
               $param =~ s/ /+/g;
               "${key}=$param"; } ( ref $val eq 'ARRAY' ? @$val : $val ));