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

dreel dreel at bk.ru
Tue Apr 22 16:30:51 BST 2008


Version Catalyst 5.7012
For example, I want to use as first arg the string: uri_for('/controller/*some_param1*','arg1','arg2') 
If *some_param1* contains non-ascii symbols it must be encoded as URI::Escape, but it missed.

I've tested it with Russian symbols:
$c->uri_for('/network/МСК') returns string http://localhost:3000/network/МСК' wrong! not-encoded!;
$c->uri_for('/network','МСК') returns string http://localhost:3000/network/%CC%D1%CA right.

So what we get if uri wasn't encoded? Browser incompatibility! IE by default encode all URIs with UTF-8,
but FF using system charset (win-1251 for me). Most of URIs become broken.

I've found out the way to correct it. In Catalyst.pm
The block where we encode @args for uri_for:
945: my $params =
946:      ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );

948: carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
    s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
unshift(@args, $path); # !!!add UNencoded $path!!!

Sorry, can't sync with svn, so plain text used (
My correction:
945: my $params =
      ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );

+	$path =~ s!/+!/!g; # strip extra slashes '///'
+	my @path_args = split('/', $path);
+	unshift(@args, @path_args);
    carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
    s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
-    unshift(@args, $path);

It this case all data will be encoded.

Any suggestions?
--
dr.eel




More information about the Catalyst mailing list