[Catalyst-commits] r11574 - trunk/Catalyst-Plugin-Unicode-Encoding/lib/Catalyst/Plugin/Unicode

chansen at dev.catalyst.perl.org chansen at dev.catalyst.perl.org
Fri Oct 16 15:54:51 GMT 2009


Author: chansen
Date: 2009-10-16 15:54:50 +0000 (Fri, 16 Oct 2009)
New Revision: 11574

Modified:
   trunk/Catalyst-Plugin-Unicode-Encoding/lib/Catalyst/Plugin/Unicode/Encoding.pm
Log:
Only pass plain scalars (PV, IV or NV) to Encode::decode


Modified: trunk/Catalyst-Plugin-Unicode-Encoding/lib/Catalyst/Plugin/Unicode/Encoding.pm
===================================================================
--- trunk/Catalyst-Plugin-Unicode-Encoding/lib/Catalyst/Plugin/Unicode/Encoding.pm	2009-10-16 15:49:39 UTC (rev 11573)
+++ trunk/Catalyst-Plugin-Unicode-Encoding/lib/Catalyst/Plugin/Unicode/Encoding.pm	2009-10-16 15:54:50 UTC (rev 11574)
@@ -38,15 +38,17 @@
 sub finalize {
     my $c = shift;
 
+    my $body = $c->response->body;
+
     return $c->next::method(@_)
-      unless $c->response->body;
+      unless defined($body);
 
     my $enc = $c->encoding;
 
     return $c->next::method(@_) 
       unless $enc;
 
-    my ($ct,$ct_enc) = $c->response->content_type;
+    my ($ct, $ct_enc) = $c->response->content_type;
 
     # Only touch 'text-like' contents
     return $c->next::method(@_)
@@ -63,7 +65,9 @@
         $c->res->content_type($c->res->content_type . "; charset=" . $enc->mime_name);
     }
 
-    $c->response->body( $c->encoding->encode( $c->response->body, $CHECK ) );
+    # Encode expects plain scalars (IV, NV or PV) and segfaults on ref's
+    $c->response->body( $c->encoding->encode( $body, $CHECK ) )
+        if ref(\$body) eq 'SCALAR';
 
     $c->next::method(@_);
 }




More information about the Catalyst-commits mailing list