Subject: | Encode::MIME::Header: wrong encoding with latin1 characters |
MIME-Q encoding works wrong if the string has high bit characters, but
no utf8 flag. The following should return an encoded two-byte utf8 string:
$ perl -MEncode=encode -e 'warn encode ("MIME-Q", "\x{fc}")'
=?UTF-8?Q?=FC?= at -e line 1.
The expected output when forcing the utf8 flag on the string:
$ perl -MEncode=encode -e 'warn encode ("MIME-Q",
substr("\x{fc}\x{100}",0,-1))'
=?UTF-8?Q?=C3=BC?= at -e line 1.
The attached patch solves the problem (by adding the missing
encode_utf8). Also, I removed decode_utf8 some lines later, because it
seems to be unnecessary in this context --- after conversion, the string
should only contain ascii characters.
Also included in the patch is the above test case.
Regards,
Slaven
Subject: | encode-mime.patch |
#
#
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'patch' program with this file as input.
#
#### End of Preamble ####
#### Patch data follows ####
diff -up 'build/Encode-2.18-C92yHm/lib/Encode/MIME/Header.pm' 'new.build/Encode-2.18-C92yHm/lib/Encode/MIME/Header.pm'
Index: ./lib/Encode/MIME/Header.pm
--- ./lib/Encode/MIME/Header.pm Sat Jun 3 22:29:02 2006
+++ ./lib/Encode/MIME/Header.pm Wed Jan 17 17:23:01 2007
@@ -174,12 +174,13 @@ sub _encode_b {
sub _encode_q {
my $chunk = shift;
+ $chunk = encode_utf8($chunk);
$chunk =~ s{
([^0-9A-Za-z])
}{
join("" => map {sprintf "=%02X", $_} unpack("C*", $1))
}egox;
- return decode_utf8( HEAD . 'Q?' . $chunk . TAIL );
+ return HEAD . 'Q?' . $chunk . TAIL;
}
1;
diff -up 'build/Encode-2.18-C92yHm/t/mime-header.t' 'new.build/Encode-2.18-C92yHm/t/mime-header.t'
Index: ./t/mime-header.t
Prereq: 2.2
--- ./t/mime-header.t Sat Jun 3 22:29:03 2006
+++ ./t/mime-header.t Wed Jan 17 17:10:45 2007
@@ -23,7 +23,7 @@ no utf8;
use strict;
#use Test::More qw(no_plan);
-use Test::More tests => 11;
+use Test::More tests => 12;
use_ok("Encode::MIME::Header");
my $eheader =<<'EOS';
@@ -116,4 +116,7 @@ is(Encode::encode('MIME-Q', $dheader), $
is(Encode::encode('MIME-Q' => $pound_1024), '=?UTF-8?Q?=C2=A31024?=',
'pound 1024');
}
+
+is(Encode::encode('MIME-Q', "\x{fc}"), '=?UTF-8?Q?=C3=BC?=', 'Encode latin1 characters');
+
__END__;
#### End of Patch data ####
#### ApplyPatch data follows ####
# Data version : 1.0
# Date generated : Wed Jan 17 17:27:34 2007
# Generated by : makepatch 2.00_11*
# Recurse directories : Yes
# Excluded files : (\A|/).*\~\Z
# (\A|/).*\.a\Z
# (\A|/).*\.bak\Z
# (\A|/).*\.BAK\Z
# (\A|/).*\.elc\Z
# (\A|/).*\.exe\Z
# (\A|/).*\.gz\Z
# (\A|/).*\.ln\Z
# (\A|/).*\.o\Z
# (\A|/).*\.obj\Z
# (\A|/).*\.olb\Z
# (\A|/).*\.old\Z
# (\A|/).*\.orig\Z
# (\A|/).*\.rej\Z
# (\A|/).*\.so\Z
# (\A|/).*\.Z\Z
# (\A|/)\.del\-.*\Z
# (\A|/)\.make\.state\Z
# (\A|/)\.nse_depinfo\Z
# (\A|/)core\Z
# (\A|/)tags\Z
# (\A|/)TAGS\Z
# p 'lib/Encode/MIME/Header.pm' 6855 1169050981 0100644
# p 't/mime-header.t' 4258 1169050245 0100755
#### End of ApplyPatch data ####
#### End of Patch kit [created: Wed Jan 17 17:27:34 2007] ####
#### Patch checksum: 76 2633 35712 ####
#### Checksum: 94 3257 21705 ####