[Catalyst-commits] r14144 - in
Catalyst-Plugin-Unicode-Encoding/trunk: .
lib/Catalyst/Plugin/Unicode t t/lib
dpetrov at dev.catalyst.perl.org
dpetrov at dev.catalyst.perl.org
Tue Nov 8 11:29:32 GMT 2011
Author: dpetrov
Date: 2011-11-08 11:29:32 +0000 (Tue, 08 Nov 2011)
New Revision: 14144
Modified:
Catalyst-Plugin-Unicode-Encoding/trunk/Changes
Catalyst-Plugin-Unicode-Encoding/trunk/lib/Catalyst/Plugin/Unicode/Encoding.pm
Catalyst-Plugin-Unicode-Encoding/trunk/t/07nested_params.t
Catalyst-Plugin-Unicode-Encoding/trunk/t/lib/TestApp2.pm
Log:
Correctly decode nested parameters
Modified: Catalyst-Plugin-Unicode-Encoding/trunk/Changes
===================================================================
--- Catalyst-Plugin-Unicode-Encoding/trunk/Changes 2011-11-07 18:08:43 UTC (rev 14143)
+++ Catalyst-Plugin-Unicode-Encoding/trunk/Changes 2011-11-08 11:29:32 UTC (rev 14144)
@@ -1,5 +1,6 @@
Revision history for Perl extension Catalyst::Plugin::Unicode::Encoding
+ - Correctly decode nested parameters
- Require Class::Data::Inheritable. RT#71674
- Require newer LWP version to avoid versions with unicode bugs.
RT#64427
Modified: Catalyst-Plugin-Unicode-Encoding/trunk/lib/Catalyst/Plugin/Unicode/Encoding.pm
===================================================================
--- Catalyst-Plugin-Unicode-Encoding/trunk/lib/Catalyst/Plugin/Unicode/Encoding.pm 2011-11-07 18:08:43 UTC (rev 14143)
+++ Catalyst-Plugin-Unicode-Encoding/trunk/lib/Catalyst/Plugin/Unicode/Encoding.pm 2011-11-08 11:29:32 UTC (rev 14144)
@@ -84,20 +84,12 @@
for my $key (qw/ parameters query_parameters body_parameters /) {
for my $value ( values %{ $c->request->{$key} } ) {
-
- # TODO: Hash support from the Params::Nested
- if ( ref $value && ref $value ne 'ARRAY' ) {
- next;
- }
- for ( ref($value) ? @{$value} : $value ) {
- # N.B. Check if already a character string and if so do not try to double decode.
- # http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg02350.html
- # this avoids exception if we have already decoded content, and is _not_ the
- # same as not encoding on output which is bad news (as it does the wrong thing
- # for latin1 chars for example)..
- next unless defined $_;
- $_ = $c->_handle_param_unicode_decoding($_);
- }
+ # N.B. Check if already a character string and if so do not try to double decode.
+ # http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg02350.html
+ # this avoids exception if we have already decoded content, and is _not_ the
+ # same as not encoding on output which is bad news (as it does the wrong thing
+ # for latin1 chars for example)..
+ $value = $c->_handle_unicode_decoding($value);
}
}
for my $value ( values %{ $c->request->uploads } ) {
@@ -139,6 +131,28 @@
return $self->next::method(@_);
}
+sub _handle_unicode_decoding {
+ my ( $self, $value ) = @_;
+
+ return unless defined $value;
+
+ if ( ref $value eq 'ARRAY' ) {
+ foreach ( @$value ) {
+ $_ = $self->_handle_unicode_decoding($_);
+ }
+ return $value;
+ }
+ elsif ( ref $value eq 'HASH' ) {
+ foreach ( values %$value ) {
+ $_ = $self->_handle_unicode_decoding($_);
+ }
+ return $value;
+ }
+ else {
+ return $self->_handle_param_unicode_decoding($value);
+ }
+}
+
sub _handle_param_unicode_decoding {
my ( $self, $value ) = @_;
my $enc = $self->encoding;
Modified: Catalyst-Plugin-Unicode-Encoding/trunk/t/07nested_params.t
===================================================================
--- Catalyst-Plugin-Unicode-Encoding/trunk/t/07nested_params.t 2011-11-07 18:08:43 UTC (rev 14143)
+++ Catalyst-Plugin-Unicode-Encoding/trunk/t/07nested_params.t 2011-11-08 11:29:32 UTC (rev 14144)
@@ -41,21 +41,24 @@
is_deeply($got, $expected, 'nested params' );
}
-TODO: {
- local $TODO = 'HASH support is broken';
-
- my ($res, $c) = ctx_request("/?foo.1=bar&foo.2=$escape_str&bar.baz=$escape_str&baz.bar.foo=$escape_str&&arr.0.1=test");
+{
+ my ($res, $c) = ctx_request("/?foo.1=bar&foo.2=$escape_str&bar.baz=$escape_str&baz.bar.foo=$escape_str&&arr.0.1=$escape_str");
my $got = $c->request->parameters;
my $expected = {
- 'foo.1' => 'bar',
- 'foo.2' => $decode_str,
- 'foo' => [undef, 'bar', $decode_str],
- 'bar' => { baz => $decode_str },
- 'baz' => { bar => { foo => $decode_str } },
+ 'foo.1' => 'bar',
+ 'foo.2' => $decode_str,
+ 'bar.baz' => $decode_str,
+ 'baz.bar.foo' => $decode_str,
+ 'arr.0.1' => $decode_str,
+ 'arr' => [ [undef, $decode_str] ],
+ 'foo' => [undef, 'bar', $decode_str],
+ 'bar' => { baz => $decode_str },
+ 'baz' => { bar => { foo => $decode_str } },
};
is( ref $got->{arr}->[0], 'ARRAY', '{arr}->[0] is ARRAY' );
+ ok( utf8::is_utf8( $got->{arr}->[0]->[1] ), '{arr}->[0]->[1] is utf8' );
ok( utf8::is_utf8( $got->{bar}{baz} ), '{bar}{baz} is utf8' );
ok( utf8::is_utf8( $got->{baz}{bar}{foo} ), '{baz}{bar}{foo} is utf8' );
is_deeply($got, $expected, 'nested params' );
Modified: Catalyst-Plugin-Unicode-Encoding/trunk/t/lib/TestApp2.pm
===================================================================
--- Catalyst-Plugin-Unicode-Encoding/trunk/t/lib/TestApp2.pm 2011-11-07 18:08:43 UTC (rev 14143)
+++ Catalyst-Plugin-Unicode-Encoding/trunk/t/lib/TestApp2.pm 2011-11-08 11:29:32 UTC (rev 14144)
@@ -2,7 +2,7 @@
use strict;
use warnings;
use base qw/Catalyst/;
-use Catalyst qw/Params::Nested Unicode::Encoding/;
+use Catalyst qw/Unicode::Encoding Params::Nested/;
__PACKAGE__->config(
encoding => $ENV{TESTAPP_ENCODING}
More information about the Catalyst-commits
mailing list