From: Wallace Reis Date: Sat, 15 Jun 2013 15:26:27 +0000 (+0000) Subject: Unicode - fix decoding process for uploads X-Git-Tag: 5.90042~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6a3355ffafb71e9a52b0ac5a533dc9cb6f8ba8b;hp=465e85c1612f42e82db5e349b88a9afc3a15e963;p=catagits%2FCatalyst-Runtime.git Unicode - fix decoding process for uploads [error] Caught exception in engine "Can't use string ("Can't call method "decode" on an"...) as a HASH ref while "strict refs" in use at Catalyst/Plugin/Unicode/Encoding.pm line 101." --- diff --git a/lib/Catalyst/Plugin/Unicode/Encoding.pm b/lib/Catalyst/Plugin/Unicode/Encoding.pm index 544d46b..6da27ad 100644 --- a/lib/Catalyst/Plugin/Unicode/Encoding.pm +++ b/lib/Catalyst/Plugin/Unicode/Encoding.pm @@ -95,15 +95,17 @@ sub prepare_uploads { for my $value ( values %{ $c->request->uploads } ) { # skip if it fails for uploads, as we don't usually want uploads touched # in any way - $_->{filename} = try { - $enc->decode( $_->{filename}, $CHECK ) - } catch { - $c->handle_unicode_encoding_exception({ - param_value => $_->{filename}, - error_msg => $_, - encoding_step => 'uploads', - }); - } for ( ref($value) eq 'ARRAY' ? @{$value} : $value ); + for my $inner_value ( ref($value) eq 'ARRAY' ? @{$value} : $value ) { + $inner_value->{filename} = try { + $enc->decode( $inner_value->{filename}, $CHECK ) + } catch { + $c->handle_unicode_encoding_exception({ + param_value => $inner_value->{filename}, + error_msg => $_, + encoding_step => 'uploads', + }); + }; + } } } diff --git a/t/unicode_plugin_no_encoding.t b/t/unicode_plugin_no_encoding.t index 5d0dfe3..a32c76b 100644 --- a/t/unicode_plugin_no_encoding.t +++ b/t/unicode_plugin_no_encoding.t @@ -20,14 +20,25 @@ my $decode_str = Encode::decode('utf-8' => $encode_str); my $escape_str = uri_escape_utf8($decode_str); check_parameter(GET "/?myparam=$escape_str"); +check_parameter(POST '/', + Content_Type => 'form-data', + Content => [ + 'myparam' => [ + "$Bin/unicode_plugin_no_encoding.t", + "$Bin/unicode_plugin_request_decode.t", + ] + ], +); sub check_parameter { my ( undef, $c ) = ctx_request(shift); - is $c->res->output => $encode_str; my $myparam = $c->req->param('myparam'); ok !utf8::is_utf8($myparam); - is $myparam => $encode_str; + unless ( $c->request->method eq 'POST' ) { + is $c->res->output => $encode_str; + is $myparam => $encode_str; + } is scalar(@TestLogger::ELOGS), 2 or diag Dumper(\@TestLogger::ELOGS);