diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-11-13 22:50:27 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-11-13 22:50:27 +0000 |
commit | fc60b131098ce5c6284e0334669647e4bbcae002 (patch) | |
tree | 3c6ed3dc81fbd5d917307d6a2889f92d6811c6d0 /t | |
parent | 5296f8c1fae401cafebff577822c2c3e4ff0b639 (diff) | |
download | perl-fc60b131098ce5c6284e0334669647e4bbcae002.tar.gz |
Fix for the :utf8 read() bug noticed by Matt Sergeant:
"large enough" Unicode characters returned more than one
as their "Unicode size".
p4raw-id: //depot/perl@12981
Diffstat (limited to 't')
-rwxr-xr-x | t/io/utf8.t | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/t/io/utf8.t b/t/io/utf8.t index 1a7d27f479..2d74cff976 100755 --- a/t/io/utf8.t +++ b/t/io/utf8.t @@ -12,9 +12,7 @@ BEGIN { no utf8; # needed for use utf8 not griping about the raw octets $| = 1; -my $total_tests = 25; -if (ord('A') == 193) { $total_tests = 24; } # EBCDIC platforms do not warn on UTF-8 -print "1..$total_tests\n"; +print "1..26\n"; open(F,"+>:utf8",'a'); print F chr(0x100).'£'; @@ -175,12 +173,38 @@ print "not " unless $x eq $chr; print "ok 24\n"; # Now we have a deformed file. -open F, "<:utf8", "a" or die $!; -$x = <F>; chomp $x; -{ local $SIG{__WARN__} = sub { print "ok 25\n"; }; -eval { sprintf "%vd\n", $x; } + +if (ord('A') == 193) { + print "ok 25 # Skip: EBCDIC\n"; # EBCDIC doesn't complain +} else { + open F, "<:utf8", "a" or die $!; + $x = <F>; chomp $x; + local $SIG{__WARN__} = sub { print "ok 25\n" }; + eval { sprintf "%vd\n", $x }; } close F; unlink('a'); +open F, ">a"; +@a = map { chr(1 << ($_ << 2)) } 0..5; # 0x1, 0x10, .., 0x100000 +print F @a; +close F; +open F, "<:utf8", "a"; +$a = 0; +for (@a) { + unless (read(F, $b, 1) == 1 && + length($b) == 1 && + ord($b) == ord($_) && + tell(F) == ($a += bytes::length($b))) { + print '# ord($_) == ', ord($_), "\n"; + print '# ord($b) == ', ord($b), "\n"; + print '# length($b) == ', length($b), "\n"; + print '# tell(F) == ', tell(F), "\n"; + print "not "; + last; + } +} +print "ok 26\n"; + +END { 1 while unlink "a" } |