Unicode - do not warn for legacy apps
Wallace Reis [Sat, 15 Jun 2013 15:23:10 +0000 (15:23 +0000)]
Lets skip the decoding process (like we do for encoding in
finalize_headers) for apps not using core encoding support,
that is, when "encoding" config bit is undef.

lib/Catalyst/Plugin/Unicode/Encoding.pm
t/unicode_plugin_no_encoding.t

index 2f2e8d5..a689f2c 100644 (file)
@@ -81,6 +81,7 @@ sub prepare_uploads {
     $c->next::method(@_);
 
     my $enc = $c->encoding;
+    return unless $enc;
 
     for my $key (qw/ parameters query_parameters body_parameters /) {
         for my $value ( values %{ $c->request->{$key} } ) {
@@ -114,6 +115,9 @@ sub prepare_action {
 
     my $ret = $c->next::method(@_);
 
+    my $enc = $c->encoding;
+    return $ret unless $enc;
+
     foreach (@{$c->req->arguments}, @{$c->req->captures}) {
       $_ = $c->_handle_param_unicode_decoding($_);
     }
index a32c76b..8034c38 100644 (file)
@@ -14,6 +14,7 @@ use Encode;
 use HTTP::Request::Common;
 use URI::Escape qw/uri_escape_utf8/;
 use HTTP::Status 'is_server_error';
+use Data::Dumper;
 
 my $encode_str = "\x{e3}\x{81}\x{82}"; # e38182 is japanese 'あ'
 my $decode_str = Encode::decode('utf-8' => $encode_str);
@@ -40,9 +41,8 @@ sub check_parameter {
         is $myparam => $encode_str;
     }
 
-    is scalar(@TestLogger::ELOGS), 2
+    is scalar(@TestLogger::ELOGS), 0
         or diag Dumper(\@TestLogger::ELOGS);
-    like $TestLogger::ELOGS[0], qr/method \"decode\"/;
 }
 
 done_testing;