[Catalyst] uri_for() doesn't encode to utf8 first argument

Dmitriy S. Sinyavskiy dreel at bk.ru
Sun Jun 1 21:34:31 BST 2008


Hello, Matt.
You write 30 мая 2008 г., 11:05:49:

MST> On Thu, May 29, 2008 at 06:17:32PM +0400, Dmitriy S. Sinyavskiy wrote:
>> Folks, what about the problem?
>> Did you test my last patch?

MST> We're still waiting for one to test.

MST> You've not yet AFAIK posted one that's (a) a full diff -ur including tests
MST> (b) has no pointless whitespaces changes.


As I remember the diff without pointless spaces was here http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg03184.html
The test http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg03247.html

If you prefer to see it together, look:

Index: t/unit_core_uri_for.t
===================================================================
--- t/unit_core_uri_for.t       (revision 7807)
+++ t/unit_core_uri_for.t       (working copy)
@@ -59,6 +59,23 @@
     'URI for undef action with query params in unicode'
 );
 
+# test encode first argument with utf-8,
+{
+$request->base( URI->new('http://127.0.0.1/') );
+
+$context->namespace('');
+
+is( Catalyst::uri_for( $context, '/animal/ёж', 'чёт', { param1 => "щуп" })->as_string,
+'http://127.0.0.1/animal/%D1%91%D0%B6/%D1%87%D1%91%D1%82?param1=%D1%89%D1%83%D0%BF',
+'URI for with first param as string in unicode'
+);
+
+is( Catalyst::uri_for( $context, '/??', '?', { param1 => "?" })->as_string,
+'http://127.0.0.1/%3F%3F/%3F?param1=%3F',
+'URI for with special char <?> in args and param'
+);
+
+
 # test with object
 is(
     Catalyst::uri_for( $context, 'quux', { param1 => $request->base } )->as_string,
Index: lib/Catalyst.pm
===================================================================
--- lib/Catalyst.pm     (revision 7807)
+++ lib/Catalyst.pm     (working copy)
@@ -948,10 +948,12 @@
     my $params =
       ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
 
+    $path =~ s!/+!/!g; # strip extra slashes '///'
+    unshift(@args, split('/', $path));
     carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
     s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
 
-    unshift(@args, $path);
+    
 
     unless (defined $path && $path =~ s!^/!!) { # in-place strip
         my $namespace = $c->namespace;



-- 
 dreel                    mailto:dreel at bk.ru
 Dmitriy S. Sinyavskiy
 Web-developer            Perl, Catalyst, MSSQL
 FGUE EZAN                Telecommunication, data transfer networks and devices.




More information about the Catalyst mailing list