[Catalyst-dev] uri_for method is broken in latest release

Daisuke Murase typester at cpan.org
Wed Jan 16 06:14:26 GMT 2008


Hi,

I noticed that current uri_for returned broken uri when multibyte chars
was passed.
Though I also checked svn repo, it still broken.

Here is a patch and test for it. (both attached)


And one more thing, why current uri_for doesn't do canonical?

In https page, I got 'https://example.com:443/foo/bar' from uri_for.
I think this is ugly.


-- 
Daisuke Murase <typester at cpan.org>
-------------- next part --------------
Index: lib/Catalyst.pm
===================================================================
--- lib/Catalyst.pm	(revision 7387)
+++ lib/Catalyst.pm	(working copy)
@@ -978,7 +978,7 @@
           $val = '' unless defined $val;
           (map {
               $_ = "$_";
-              utf8::encode( $_ );
+              utf8::encode( $_ ) if utf8::is_utf8($_);
               # using the URI::Escape pattern here so utf8 chars survive
               s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go;
               s/ /+/g;
-------------- next part --------------
use strict;
use warnings;

use FindBin;
use File::Spec;
use lib File::Spec->catfile($FindBin::Bin, 'lib');

use Test::More;

plan tests => 3;

use_ok('TestApp');

my $base = 'http://127.0.0.1';

my $request = Catalyst::Request->new({
    base => URI->new($base),
});

my $context = TestApp->new({
    request => $request,
});


my $uri_with_multibyte = URI->new($base);
$uri_with_multibyte->path('/');
$uri_with_multibyte->query_form(
    name => '????',
);


# multibyte with utf8 bytes
is($context->uri_for('/', { name => '????' }), $uri_with_multibyte, 'uri with utf8 bytes query');


# multibyte with utf8 string
is($context->uri_for('/', { name => "\x{6751}\x{702c}\x{5927}\x{8f14}" }), $uri_with_multibyte, 'uri with utf8 string query');


More information about the Catalyst-dev mailing list