From eb7e197b44fe0299233d423ce8184ba0cffc3883 Mon Sep 17 00:00:00 2001 From: Nick Ing-Simmons Date: Mon, 21 Oct 2002 17:50:44 +0000 Subject: [PATCH] Test UTF-8 encoded input to Encode::XS::decode and fix it. p4raw-id: //depot/perlio@18043 --- ext/Encode/Encode.xs | 3 +++ ext/Encode/t/mime-header.t | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ext/Encode/Encode.xs b/ext/Encode/Encode.xs index 57fc9a0..d422144 100644 --- a/ext/Encode/Encode.xs +++ b/ext/Encode/Encode.xs @@ -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); diff --git a/ext/Encode/t/mime-header.t b/ext/Encode/t/mime-header.t index 745fb1c..d0274dc 100644 --- a/ext/Encode/t/mime-header.t +++ b/ext/Encode/t/mime-header.t @@ -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 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?= +To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= +CC: =?ISO-8859-1?Q?Andr=E9?= Pirard +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: 小飼 弾 To: dankogai@dan.co.jp (小飼=Kogai, 弾=Dan) -- 2.7.4