Skip Menu |

This queue is for tickets about the Catalyst-Runtime CPAN distribution.

Report information
The Basics
Id: 32711
Status: resolved
Priority: 0/
Queue: Catalyst-Runtime

People
Owner: Nobody in particular
Requestors: knut-olav [...] hoven.ws
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 5.7012
Fixed in: (no value)



Subject: Configuration parameter for utf8::encode in uri_for
Added two files, one patch to add a configurable parameter for turning on/off the use of utf8::encode in the uri_for method, and the other file is a test for testing this. The test file is the same as unit_core_uri_for.t, but without the use of utf8::encode.
Subject: unit_core_uri_for_no_utf8_encode.t
use strict; use warnings; use Test::More tests => 14; use URI; use_ok('Catalyst'); Catalyst->config( 'utf8' => { 'encode' => 0, }, ); my $request = Catalyst::Request->new( { base => URI->new('http://127.0.0.1/foo') } ); my $context = Catalyst->new( { request => $request, namespace => 'yada', } ); is( Catalyst::uri_for( $context, '/bar/baz' )->as_string, 'http://127.0.0.1/foo/bar/baz', 'URI for absolute path' ); is( Catalyst::uri_for( $context, 'bar/baz' )->as_string, 'http://127.0.0.1/foo/yada/bar/baz', 'URI for relative path' ); is( Catalyst::uri_for( $context, '', 'arg1', 'arg2' )->as_string, 'http://127.0.0.1/foo/yada/arg1/arg2', 'URI for undef action with args' ); is( Catalyst::uri_for( $context, '../quux' )->as_string, 'http://127.0.0.1/foo/quux', 'URI for relative dot path' ); is( Catalyst::uri_for( $context, 'quux', { param1 => 'value1' } )->as_string, 'http://127.0.0.1/foo/yada/quux?param1=value1', 'URI for undef action with query params' ); is (Catalyst::uri_for( $context, '/bar/wibble?' )->as_string, 'http://127.0.0.1/foo/bar/wibble%3F', 'Question Mark gets encoded' ); is( Catalyst::uri_for( $context, qw/bar wibble?/, 'with space' )->as_string, 'http://127.0.0.1/foo/yada/bar/wibble%3F/with%20space', 'Space gets encoded' ); # test with utf-8 is( Catalyst::uri_for( $context, 'quux', { param1 => "\x{2620}" } )->as_string, 'http://127.0.0.1/foo/yada/quux?param1=%E2%98%A0', 'URI for undef action with query params in unicode' ); # test with object is( Catalyst::uri_for( $context, 'quux', { param1 => $request->base } )->as_string, 'http://127.0.0.1/foo/yada/quux?param1=http%3A%2F%2F127.0.0.1%2Ffoo', 'URI for undef action with query param as object' ); $request->base( URI->new('http://localhost:3000/') ); $request->match( 'orderentry/contract' ); is( Catalyst::uri_for( $context, '/Orderentry/saveContract' )->as_string, 'http://localhost:3000/Orderentry/saveContract', 'URI for absolute path' ); { $request->base( URI->new('http://127.0.0.1/') ); $context->namespace(''); is( Catalyst::uri_for( $context, '/bar/baz' )->as_string, 'http://127.0.0.1/bar/baz', 'URI with no base or match' ); # test "0" as the path is( Catalyst::uri_for( $context, qw/0 foo/ )->as_string, 'http://127.0.0.1/0/foo', '0 as path is ok' ); } # test with undef -- no warnings should be thrown { my $warnings = 0; local $SIG{__WARN__} = sub { $warnings++ }; Catalyst::uri_for( $context, '/bar/baz', { foo => undef } )->as_string, is( $warnings, 0, "no warnings emitted" ); }
Subject: Catalyst.pm-utf8-encode.patch
--- Catalyst.pm.orig 2008-01-27 18:07:51.000000000 +0100 +++ Catalyst.pm 2008-01-27 18:29:21.000000000 +0100 @@ -63,6 +63,12 @@ __PACKAGE__->response_class('Catalyst::Response'); __PACKAGE__->stats_class('Catalyst::Stats'); +__PACKAGE__->config( + 'utf8' => { + 'encode' => 1, + }, +); + # Remember to update this in Catalyst::Runtime as well! our $VERSION = '5.7012'; @@ -673,7 +679,6 @@ --- db: dsn:SQLite:foo.db - =cut sub config { @@ -920,6 +925,9 @@ contain GET parameter key/value pairs, which will be appended to the URI in standard fashion. +GET parameters will by default be converted with L<utf8/encode>. To disable +this behaviour set the configuration parameter C<{utf8}{encode}> to C<0>. + Instead of C<$path>, you can also optionally pass a C<$action> object which will be resolved to a path using C<< $c->dispatcher->uri_for_action >>; if the first element of @@ -978,7 +986,7 @@ $val = '' unless defined $val; (map { $_ = "$_"; - utf8::encode( $_ ); + utf8::encode( $_ ) if $c->config->{'utf8'}{'encode'}; # using the URI::Escape pattern here so utf8 chars survive s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go; s/ /+/g;
Before we even attempt to apply this patch, can you explain in some detail what is wrong with the way we currently do things, and why this option would be useful? Thank you.
I believe that this issue has been fixed in recent Catalyst releases, therefore I'm resolving it as this ticket hasn't been updated by the original requester in a long time. Please feel free to re-open if you thing there is still an issue here. Cheers t0m