Skip Menu |

This queue is for tickets about the Catalyst-Plugin-Unicode-Encoding CPAN distribution.

Report information
The Basics
Id: 69677
Status: resolved
Priority: 0/
Queue: Catalyst-Plugin-Unicode-Encoding

People
Owner: Nobody in particular
Requestors: bokutin [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.7
Fixed in: (no value)



Subject: nonworking if ShiftJIS charaset specified
Hi. I found a bug. In case non upper case charset specified in $c->res->content_type, error occrued. Please check this code!! Thanks. Index: lib/Catalyst/Plugin/Unicode/Encoding.pm =================================================================== --- lib/Catalyst/Plugin/Unicode/Encoding.pm (revision 14051) +++ lib/Catalyst/Plugin/Unicode/Encoding.pm (working copy) @@ -55,7 +55,7 @@ unless $c->response->content_type =~ /^text|xml$|javascript$/; if ($ct_enc && $ct_enc =~ /charset=(.*?)$/) { - if (uc($1) ne $enc->mime_name) { + if (uc($1) ne uc($enc->mime_name)) { $c->log->debug("Unicode::Encoding is set to encode in '" . $enc->mime_name . "', content type is '$1', not encoding ");
Subject: encoding_diff.txt
Index: t/04live.t =================================================================== --- t/04live.t (revision 14051) +++ t/04live.t (working copy) @@ -81,5 +81,16 @@ is ($got, $exp, 'content octets are UTF-8'); } +{ + $mech->get_ok('http://localhost/shift_jis', 'get shift_jis'); + is ($mech->response->header('Content-Type'), 'text/plain; charset=Shift_JIS', + 'Content-Type with charset'); + + my $exp = "\xE3\x81\xBB\xE3\x81\x92"; + my $got = Encode::encode_utf8($mech->content); + + is ($got, $exp, 'content octets are Shift_JIS'); +} + done_testing; Index: t/lib/TestApp/Controller/Root.pm =================================================================== --- t/lib/TestApp/Controller/Root.pm (revision 14051) +++ t/lib/TestApp/Controller/Root.pm (working copy) @@ -45,6 +45,14 @@ $c->response->body('LATIN SMALL LETTER E WITH ACUTE: é'); } +sub shift_jis :Local { + my ($self, $c) = @_; + my $data = "ほげ"; # hoge! + $c->response->body($data); # should be decoded + $c->res->content_type('text/plain; charset=Shift_JIS'); + $c->encoding("Shift_JIS"); +} + sub file :Local { my ($self, $c) = @_; close *STDERR; # i am evil. Index: lib/Catalyst/Plugin/Unicode/Encoding.pm =================================================================== --- lib/Catalyst/Plugin/Unicode/Encoding.pm (revision 14051) +++ lib/Catalyst/Plugin/Unicode/Encoding.pm (working copy) @@ -55,7 +55,7 @@ unless $c->response->content_type =~ /^text|xml$|javascript$/; if ($ct_enc && $ct_enc =~ /charset=(.*?)$/) { - if (uc($1) ne $enc->mime_name) { + if (uc($1) ne uc($enc->mime_name)) { $c->log->debug("Unicode::Encoding is set to encode in '" . $enc->mime_name . "', content type is '$1', not encoding ");
Hi. I have my local fixed lib/Catalyst/Plugin/Unicode/Encodings.pm on production environment because this bug stayed. I fail to understand this line. <pre> if (uc($1) ne $enc->mime_name) { </pre> Most charset names are consist of upper cases only, but some charset names are consist of mix cases. http://www.iana.org/assignments/character-sets <pre> use Modern::Perl; use Encode; my @all_encodings = map { Encode::find_encoding($_) } Encode->encodings(":all"); my @has_mime_name = grep { $_->mime_name } @all_encodings; my @uc_chars_only = grep { $_->mime_name eq uc($_->mime_name) } @has_mime_name; my @not_uc_chars_only = grep { $_->mime_name ne uc($_->mime_name) } @has_mime_name; say "all encodings: ".@all_encodings; say "has mime_name: ".@has_mime_name; say "uc chars only: ".@uc_chars_only; say "!uc chars_only: ".@not_uc_chars_only; die unless @has_mime_name == (@uc_chars_only+@not_uc_chars_only); for (@not_uc_chars_only) { say "\t".$_->mime_name; } # all encodings: 124 # has mime_name: 67 # uc chars only: 53 # !uc chars_only: 14 # Adobe-Standard-Encoding # Adobe-Symbol-Encoding # Big5-HKSCS # windows-1250 # windows-1251 # windows-1252 # windows-1253 # windows-1254 # windows-1255 # windows-1256 # windows-1257 # windows-1258 # hp-roman8 # Shift_JIS </pre> My problem case below... <pre> if (uc("Shift_JIS") ne Encode::find_encoding("Shift_JIS")->mime_name) { </pre> Cheers Tomohiro Hosaka
This issue should be fixed in the latest release. Thank you for the bug, patch and tests - much appreciated!