[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.8-168-g3fcf977

? sunnavy sunnavy at bestpractical.com
Fri Oct 8 02:54:12 EDT 2010


The branch, 3.8-trunk has been updated
       via  3fcf977a7f1fa77f581eab7ee7d221d4152b6ff7 (commit)
      from  f7b602e68d04a92b0a860403720cc61cb868cc36 (commit)

Summary of changes:
 lib/RT/Interface/Web/Handler.pm |   42 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit 3fcf977a7f1fa77f581eab7ee7d221d4152b6ff7
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Oct 8 14:48:08 2010 +0800

    customize out_method to encode right

diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index cd54e85..b123734 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -153,7 +153,47 @@ sub NewApacheHandler {
 
 sub NewCGIHandler {
     require HTML::Mason::CGIHandler;
-    return NewHandler('HTML::Mason::CGIHandler', @_);
+    return NewHandler(
+        'HTML::Mason::CGIHandler',
+        out_method => sub {
+            my $m = HTML::Mason::Request->instance;
+            my $r = $m->cgi_request;
+
+            # Send headers if they have not been sent by us or by user.
+            $r->send_http_header unless $r->http_header_sent;
+
+            # Set up a default
+            $r->content_type('text/html; charset=utf-8')
+                unless $r->content_type;
+
+            if ( $r->content_type =~ /charset=([\w-]+)$/ ) {
+                my $enc = $1;
+                if ( lc $enc !~ /utf-?8$/ ) {
+                    for my $str (@_) {
+                        next unless $str;
+
+                        # only encode perl internal strings
+                        next unless utf8::is_utf8($str);
+                        $str = Encode::encode( $enc, $str );
+                    }
+                }
+            }
+
+            # default to utf8 encoding
+            for my $str (@_) {
+                next unless $str;
+                next unless utf8::is_utf8($str);
+                $str = Encode::encode( 'utf8', $str );
+            }
+
+            # We could perhaps install a new, faster out_method here that
+            # wouldn't have to keep checking whether headers have been
+            # sent and what the $r->method is.  That would require
+            # additions to the Request interface, though.
+            print STDOUT grep {defined} @_;
+        },
+        @_
+    );
 }
 
 sub NewHandler {

-----------------------------------------------------------------------


More information about the Rt-commit mailing list