[Catalyst-commits] r11763 - Catalyst-Plugin-Unicode-Encoding/branches/support_upload_filename/lib/Catalyst/Plugin/Unicode

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Thu Nov 5 01:49:47 GMT 2009


Author: t0m
Date: 2009-11-05 01:49:46 +0000 (Thu, 05 Nov 2009)
New Revision: 11763

Modified:
   Catalyst-Plugin-Unicode-Encoding/branches/support_upload_filename/lib/Catalyst/Plugin/Unicode/Encoding.pm
Log:
Controversially (maybe?) do the right thing to avoid exceptions on already decoded content

Modified: Catalyst-Plugin-Unicode-Encoding/branches/support_upload_filename/lib/Catalyst/Plugin/Unicode/Encoding.pm
===================================================================
--- Catalyst-Plugin-Unicode-Encoding/branches/support_upload_filename/lib/Catalyst/Plugin/Unicode/Encoding.pm	2009-11-05 01:39:56 UTC (rev 11762)
+++ Catalyst-Plugin-Unicode-Encoding/branches/support_upload_filename/lib/Catalyst/Plugin/Unicode/Encoding.pm	2009-11-05 01:49:46 UTC (rev 11763)
@@ -87,12 +87,19 @@
             if ( ref $value && ref $value ne 'ARRAY' ) {
                 next;
             }
-
-            $_ = $enc->decode( $_, $CHECK ) for ( ref($value) ? @{$value} : $value );
+            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)..
+                $_ = Encode::is_utf8( $_ ) ? $_ : $enc->decode( $_, $CHECK );
+            }
         }
     }
     for my $value ( values %{ $c->request->uploads } ) {
-        $_->{filename} = $enc->decode( $_->{filename}, $CHECK ) for ( ref($value) eq 'ARRAY' ? @{$value} : $value );
+        $_->{filename} = $enc->decode( $_->{filename}, $CHECK )
+            for ( ref($value) eq 'ARRAY' ? @{$value} : $value );
     }
 }
 




More information about the Catalyst-commits mailing list