Permalink
Browse files

Item12027: Foswiki::Logger::PlainFile: properly handle non-Unicode UT…

…F-8 strings

... maybe that sounds a bit weird, so here's an explanation.

In theory, you use Perl's Unicode-aware strings in modern Perl code. The code
here assumed that PerlIO would do the right thing for byte strings
(traditional non-Unicode-aware strings), too... but in this case it doesn't if
the site charset is UTF-8. In that case, the byte string will contain UTF-8
but Perl will assume that it's the system's native locale (or something like
that), and thus the PerlIO encoding layer will encode the UTF-8 *again*,
resulting in "double UTF-8 encoding".

Hence, PerlIO encoding should only be used if we're dealing with a proper
Unicode string.


git-svn-id: http://svn.foswiki.org/trunk@17201 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information...
JanKrueger JanKrueger
JanKrueger authored and JanKrueger committed Jan 2, 2014
1 parent 57cc4ac commit 132db038d1f43025df99637a08cbfe169b36beae
Showing with 5 additions and 3 deletions.
  1. +5 −3 core/lib/Foswiki/Logger/PlainFile.pm
@@ -104,10 +104,12 @@ sub log {
my $file;
my $mode = '>>';
# Item10764, SMELL UNICODE: actually, perhaps we should open the stream this
# way for any encoding, not just utf8. Babar says: check what Catalyst does.
# Item10764, SMELL UNICODE: actually, perhaps we should open the stream this
# way for any encoding, not just utf8. Babar says: check what Catalyst does.
# Item12027: this only makes sense for Unicode strings, not UTF-8 byte strings
if ( $Foswiki::cfg{Site}{CharSet}
&& $Foswiki::cfg{Site}{CharSet} =~ /^utf-?8$/ )
&& $Foswiki::cfg{Site}{CharSet} =~ /^utf-?8$/
&& utf8::is_utf8($message) )
{
$mode .= ":encoding($Foswiki::cfg{Site}{CharSet})";
}

0 comments on commit 132db03

Please sign in to comment.