Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APItest/t/utf8_warn_base: Add tests #22646

Open
wants to merge 2 commits into
base: blead
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions ext/XS-APItest/t/utf8_warn_base.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,12 @@ ($)
# We try various combinations of malformations that can occur
foreach my $short (0, 1) {
next if $skip_most_tests && $short;
foreach my $unexpected_noncont (0, 1) {
# Insert an unexpected non-continuation in every possible position
my $unexpected_noncont;
for ($unexpected_noncont = $length - $short - 1;
$unexpected_noncont > 0;
$unexpected_noncont--)
{
next if $skip_most_tests && $unexpected_noncont;
foreach my $overlong (0, 1) {
next if $overlong && $skip_most_tests;
Expand Down Expand Up @@ -1318,11 +1323,14 @@ ($)

if ($unexpected_noncont) {

# To force this malformation, change the final continuation
# byte into a start byte.
my $pos = ($short) ? -2 : -1;
substr($this_bytes, $pos, 1) = $known_start_byte;
$this_expected_len--;
# The overlong tweaking above changes the first bytes to
# specified values; we better not override those.
next if $overlong;

# To force this malformation, change a continuation byte into a
# start byte.
substr($this_bytes, $unexpected_noncont, 1) = $known_start_byte;
$this_expected_len = $unexpected_noncont;
}

# The whole point of a test that is malformed from the beginning
Expand Down Expand Up @@ -1551,9 +1559,9 @@ ($)
# Test partial character handling, for each byte not a
# full character
my $did_test_partial = 0;
for (my $j = 1; $j < $this_length - 1; $j++) {
for (my $byte_count = 1; $byte_count < $this_expected_len - 1; $byte_count++) {
$did_test_partial = 1;
my $partial = substr($this_bytes, 0, $j);
my $partial = substr($this_bytes, 0, $byte_count);
my $ret_should_be;
my $comment;
if ($disallow_type || $malformations_name) {
Expand Down Expand Up @@ -1582,7 +1590,7 @@ ($)
$needed_to_tell = $dl if $dl < $needed_to_tell;
}

if ($j < $needed_to_tell) {
if ($byte_count < $needed_to_tell) {
$ret_should_be = 1;
$comment .= ", but need $needed_to_tell"
. " bytes to discern:";
Expand All @@ -1596,7 +1604,7 @@ ($)
undef @warnings_gotten;

$ret = test_is_utf8_valid_partial_char_flags($partial,
$j, $disallow_flags);
$byte_count, $disallow_flags);
is($ret, $ret_should_be,
" And is_utf8_valid_partial_char_flags("
. display_bytes($partial)
Expand Down
Loading