Subject: | request captures are not encoded |
It seems request captures are not encoded at all.
I noticed this when I implemented a tagging system where the tag itself
becomes part of the URI .../tag/Bücher .
So I wrote a patch and a test.
Or did I just miss the right button in Catalyst?
Subject: | capturesencoded.diff |
Index: t/aggregate/unit_core_uri_for_action.t
===================================================================
--- t/aggregate/unit_core_uri_for_action.t (Revision 11487)
+++ t/aggregate/unit_core_uri_for_action.t (Arbeitskopie)
@@ -2,13 +2,14 @@
use strict;
use warnings;
+use utf8;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::More;
-plan tests => 30;
+plan tests => 32;
use_ok('TestApp');
@@ -173,5 +174,15 @@
like $@, qr{^Can't find action for path '/does/not/exist'},
'uri_for_action croaks on nonexistent path';
+ # test with utf-8
+ is( $context->uri_for_action($chained_action, ["\x{2620}fracture"], 3),
+ 'http://127.0.0.1/foo/chained/foo/%E2%98%A0fracture/end/3',
+ 'uri_for_action with one unicode capture'
+ );
+
+ is( $context->uri_for_action($action_needs_two, ["ätoø", "panic: \x{2620}"], 'xxx'),
+ 'http://127.0.0.1/foo/chained/foo2/%C3%A4to%C3%B8/panic:%20%E2%98%A0/end2/xxx',
+ 'uri_for_action with two unicode captures'
+ );
}
Index: lib/Catalyst.pm
===================================================================
--- lib/Catalyst.pm (Revision 11487)
+++ lib/Catalyst.pm (Arbeitskopie)
@@ -1250,6 +1250,7 @@
my $captures = ( scalar @args && ref $args[0] eq 'ARRAY'
? shift(@args)
: [] );
+ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @$captures;
my $action = $path;
$path = $c->dispatcher->uri_for_action($action, $captures);
if (not defined $path) {