]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
Fix double UTF-8 decode on Perl < 5.20 with upgraded Encode.pm
authorAnders Kaseorg <andersk@mit.edu>
Sun, 25 Jan 2015 04:49:23 +0000 (23:49 -0500)
committerSimon McVittie <smcv@debian.org>
Sun, 1 Mar 2015 12:43:20 +0000 (12:43 +0000)
Commit feb21ebfacb341fc34244e1c9b8557fd81d1dfc1 added a
safe_decode_utf8 function that avoids double decoding on Perl 5.20.
But the Perl behavior change actually happened in Encode.pm 2.53
(https://github.com/dankogai/p5-encode/pull/11).  Although Perl 5.20
is the first Perl version to bundle an affected version of Encode.pm,
it’s also possible to upgrade Encode.pm independently; for example,
Fedora 20 has Perl 5.18.4 with Encode.pm 2.54.  On such a system,
editing a non-ASCII file still fails with errors like

Error: Cannot decode string with wide characters at
/usr/lib64/perl5/vendor_perl/Encode.pm line 216.

There doesn’t seem to be any reason not to check Encode::is_utf8 on
old versions too, so just remove the version check altogether.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Bug-Debian: https://bugs.debian.org/776181

IkiWiki/CGI.pm

index 61af830f859bcd4407cb845472a72d44eeed5c67..d801c72a00c1be4d2a8bae752822de91b3c1e69f 100644 (file)
@@ -124,9 +124,7 @@ sub decode_cgi_utf8 ($) {
 
 sub safe_decode_utf8 ($) {
     my $octets = shift;
-    # call decode_utf8 on >= 5.20 only if it's not already decoded,
-    # otherwise it balks, on < 5.20, always call it
-    if ($] < 5.02 || !Encode::is_utf8($octets)) {
+    if (!Encode::is_utf8($octets)) {
         return decode_utf8($octets);
     }
     else {