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

Matt S Trout dbix-class at trout.me.uk
Tue Apr 22 18:01:53 BST 2008


On Tue, Apr 22, 2008 at 07:30:51PM +0400, dreel wrote:
> 
> 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?

$c->uri_for($c->controller('Network')->action_for('root'), 'some_param1', 'arg1', 'arg2');

is a better approach to this and will encode correctly.

Your patch looks like it -might- work, but you don't seem to have provided
an addition to the test suite so we can't apply it.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list