summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-03-09 13:50:57 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-03-09 13:50:57 +0000
commit52d2e0f43e4c92315f9f6c027571388b7bc65ff5 (patch)
tree9d3a5ecb667da98fcf89f05c2b945974ed5cf5ed
parent5460b889677b9f352c882dbcd4ad4470b8281664 (diff)
downloadperl-52d2e0f43e4c92315f9f6c027571388b7bc65ff5.tar.gz
From Inaba Hiroto: DATA wasn't properly utf8ed
under 'use encoding'. p4raw-id: //depot/perl@18865
-rw-r--r--MANIFEST1
-rw-r--r--ext/Encode/MANIFEST1
-rw-r--r--ext/Encode/t/enc_data.t24
-rw-r--r--toke.c25
4 files changed, 49 insertions, 2 deletions
diff --git a/MANIFEST b/MANIFEST
index 6fec033605..11ea10ca2d 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -261,6 +261,7 @@ ext/Encode/t/big5-hkscs.utf test data
ext/Encode/t/CJKT.t test script
ext/Encode/t/Encode.t test script
ext/Encode/t/Encoder.t test script
+ext/Encode/t/enc_data.t test script for utf8 DATA
ext/Encode/t/enc_eucjp.t test script
ext/Encode/t/enc_module.enc test data for t/enc_module.t
ext/Encode/t/enc_module.t test script
diff --git a/ext/Encode/MANIFEST b/ext/Encode/MANIFEST
index 2705308a64..0eb87ed1ec 100644
--- a/ext/Encode/MANIFEST
+++ b/ext/Encode/MANIFEST
@@ -62,6 +62,7 @@ t/big5-eten.enc test data
t/big5-eten.utf test data
t/big5-hkscs.enc test data
t/big5-hkscs.utf test data
+t/enc_data.t test script for utf8 DATA
t/enc_eucjp.t test script
t/enc_module.enc test data for t/enc_module.t
t/enc_module.t test script
diff --git a/ext/Encode/t/enc_data.t b/ext/Encode/t/enc_data.t
new file mode 100644
index 0000000000..f47d083204
--- /dev/null
+++ b/ext/Encode/t/enc_data.t
@@ -0,0 +1,24 @@
+use encoding 'euc-jp';
+use Test::More tests => 1;
+
+my @a;
+
+while (<DATA>) {
+ chomp;
+ tr/ぁ-んァ-ン/ァ-ンぁ-ん/;
+ push @a, $_;
+}
+
+SKIP: {
+ skip("pre-5.8.1 does not do utf8 DATA", 1) if $] < 5.008001;
+ ok(@a == 3 &&
+ $a[0] eq "コレハDATAふぁいるはんどるノてすとデス。" &&
+ $a[1] eq "日本語ガチャント変換デキルカ" &&
+ $a[2] eq "ドウカノてすとヲシテイマス。",
+ "utf8 (euc-jp) DATA")
+}
+
+__DATA__
+これはDATAファイルハンドルのテストです。
+日本語がちゃんと変換できるか
+どうかのテストをしています。
diff --git a/toke.c b/toke.c
index 5214989d59..4e5a977844 100644
--- a/toke.c
+++ b/toke.c
@@ -4188,8 +4188,29 @@ Perl_yylex(pTHX)
}
#endif
#ifdef PERLIO_LAYERS
- if (UTF && !IN_BYTES)
- PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
+ if (!IN_BYTES) {
+ if (UTF)
+ PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
+ else if (PL_encoding) {
+ SV *name;
+ dSP;
+ ENTER;
+ SAVETMPS;
+ PUSHMARK(sp);
+ EXTEND(SP, 1);
+ XPUSHs(PL_encoding);
+ PUTBACK;
+ call_method("name", G_SCALAR);
+ SPAGAIN;
+ name = POPs;
+ PUTBACK;
+ PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
+ Perl_form(aTHX_ ":encoding(%"SVf")",
+ name));
+ FREETMPS;
+ LEAVE;
+ }
+ }
#endif
PL_rsfp = Nullfp;
}