[Bps-public-commit] HTTP-Server-Simple-Mason branch, master, updated. 0.13-2-gc8af3e7
? sunnavy
sunnavy at bestpractical.com
Tue Aug 17 06:52:09 EDT 2010
The branch, master has been updated
via c8af3e79ade8e281b6a2f43c8213068184658031 (commit)
from be45f8e18412fec0712624698e522ec6b0737051 (commit)
Summary of changes:
lib/HTTP/Server/Simple/Mason.pm | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
- Log -----------------------------------------------------------------
commit c8af3e79ade8e281b6a2f43c8213068184658031
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Aug 17 18:52:10 2010 +0800
encode only if the string is utf8
diff --git a/lib/HTTP/Server/Simple/Mason.pm b/lib/HTTP/Server/Simple/Mason.pm
index 4a5ed1e..ef8fcc5 100644
--- a/lib/HTTP/Server/Simple/Mason.pm
+++ b/lib/HTTP/Server/Simple/Mason.pm
@@ -202,15 +202,26 @@ sub new_handler {
$r->content_type('text/html; charset=utf-8')
unless $r->content_type;
- if ($r->content_type =~ /charset=([\w-]+)$/ ) {
+ if ( $r->content_type =~ /charset=([\w-]+)$/ ) {
my $enc = $1;
- if (lc($enc) =~ /^utf-?8$/) {
- binmode *STDOUT, ':utf8'; # faster than :encoding
- }
- else {
- binmode *STDOUT, ":encoding($enc)";
+ 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
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list