Test UTF-8 encoded input to Encode::XS::decode and fix it.
Nick Ing-Simmons [Mon, 21 Oct 2002 17:50:44 +0000 (17:50 +0000)]
p4raw-id: //depot/perlio@18043

ext/Encode/Encode.xs
ext/Encode/t/mime-header.t

index 57fc9a0..d422144 100644 (file)
@@ -388,6 +388,9 @@ int check
 CODE:
 {
     encode_t *enc = INT2PTR(encode_t *, SvIV(SvRV(obj)));
+    if (SvUTF8(src)) {
+       sv_utf8_downgrade(src, FALSE);
+    }
     ST(0) = encode_method(aTHX_ enc, enc->t_utf8, src, check);
     SvUTF8_on(ST(0));
     XSRETURN(1);
index 745fb1c..d0274dc 100644 (file)
@@ -23,7 +23,7 @@ no utf8;
 
 use strict;
 #use Test::More qw(no_plan);
-use Test::More tests => 6;
+use Test::More tests => 7;
 use_ok("Encode::MIME::Header");
 
 my $eheader =<<'EOS';
@@ -41,10 +41,21 @@ CC: Andr\xE9 Pirard <PIRARD\@vm1.ulg.ac.be>
 Subject: If you can read this you understand the example.
 EOS
 
-is(Encode::decode('MIME-Header', $eheader), $dheader, "decode (RFC2047)");
+is(Encode::decode('MIME-Header', $eheader), $dheader, "decode ASCII (RFC2047)");
 
 use utf8;
 
+my $uheader =<<'EOS';
+From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>
+To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>
+CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>
+Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
+ =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=
+EOS
+
+is(Encode::decode('MIME-Header', $uheader), $dheader, "decode UTF-8 (RFC2047)");
+
+
 $dheader=<<'EOS';
 From: 小飼 弾 <dankogai@dan.co.jp>
 To: dankogai@dan.co.jp (小飼=Kogai, 弾=Dan)