-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix appending correct number of Unicode replacement characters
When truncated UTF-8 sequence was followed by another truncated UTF-8 sequence optionally followed by UTF-8 invariant at the end of string and first sequence in case it would have been not-truncated is longer as current string then the whole sequence was replaced just by one Unicode replacement characters, instead of two (for each invalid/truncated UTF-8 sequence). This happened also in case Encode was called with STOP_AT_PARTIAL flag.
- Loading branch information
Showing
3 changed files
with
53 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
BEGIN { | ||
if ($ENV{'PERL_CORE'}) { | ||
chdir 't'; | ||
unshift @INC, '../lib'; | ||
} | ||
require Config; import Config; | ||
if ($Config{'extensions'} !~ /\bEncode\b/) { | ||
print "1..0 # Skip: Encode was not built\n"; | ||
exit 0; | ||
} | ||
if (ord("A") == 193) { | ||
print "1..0 # Skip: EBCDIC\n"; | ||
exit 0; | ||
} | ||
$| = 1; | ||
} | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Encode; | ||
use PerlIO::encoding; | ||
$PerlIO::encoding::fallback &= ~(Encode::WARN_ON_ERR|Encode::PERLQQ); | ||
|
||
use Test::More tests => 6; | ||
|
||
is(decode("UTF-8", "\xfd\xfe"), "\x{fffd}" x 2); | ||
is(decode("UTF-8", "\xfd\xfe\xff"), "\x{fffd}" x 3); | ||
is(decode("UTF-8", "\xfd\xfe\xff\xe0"), "\x{fffd}" x 4); | ||
is(decode("UTF-8", "\xfd\xfe\xff\xe0\xe1"), "\x{fffd}" x 5); | ||
|
||
my $str = ("x" x 1023) . "\xfd\xfe\xffx"; | ||
open my $fh, '<:encoding(UTF-8)', \$str; | ||
my $str2 = <$fh>; | ||
close $fh; | ||
is($str2, ("x" x 1023) . ("\x{fffd}" x 3) . "x"); | ||
|
||
TODO: { | ||
local $TODO = "bug in perlio"; | ||
my $str = ("x" x 1023) . "\xfd\xfe\xff"; | ||
open my $fh, '<:encoding(UTF-8)', \$str; | ||
my $str2 = <$fh>; | ||
close $fh; | ||
is($str2, ("x" x 1023) . ("\x{fffd}" x 3)); | ||
} |