From Inaba Hiroto: DATA wasn't properly utf8ed
Jarkko Hietaniemi [Sun, 9 Mar 2003 13:50:57 +0000 (13:50 +0000)]
under 'use encoding'.

p4raw-id: //depot/perl@18865

MANIFEST
ext/Encode/MANIFEST
ext/Encode/t/enc_data.t [new file with mode: 0644]
toke.c

index 6fec033..11ea10c 100644 (file)
--- 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
index 2705308..0eb87ed 100644 (file)
@@ -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 (file)
index 0000000..f47d083
--- /dev/null
@@ -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 5214989..4e5a977 100644 (file)
--- 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;
            }