-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ext/mbstring: move unsigned 32 bit integer tests to a new test (#12891)
And only run it on 64 bit architectures as those are floats on 32 bit.
- Loading branch information
Showing
4 changed files
with
74 additions
and
27 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
58 changes: 58 additions & 0 deletions
58
ext/mbstring/tests/mb_decode_numericentity_large_ints.phpt
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,58 @@ | ||
--TEST-- | ||
mb_decode_numericentity() with 0xFFFFFFFF in conversion map | ||
--EXTENSIONS-- | ||
mbstring | ||
--SKIPIF-- | ||
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> | ||
--FILE-- | ||
<?php | ||
|
||
function varDumpToString($var) | ||
{ | ||
ob_start(); | ||
var_dump($var); | ||
return trim(ob_get_clean()); | ||
} | ||
|
||
function test($desc, $str, $expected, $convmap, $encoding) { | ||
$result = mb_decode_numericentity($str, $convmap, $encoding); | ||
echo $desc, ": ", varDumpToString($str), " => ", varDumpToString($result); | ||
if ($result === $expected) | ||
echo " (Good)\n"; | ||
else | ||
echo " (BAD; expected ", varDumpToString($expected), ")\n"; | ||
} | ||
|
||
function testNonAscii($desc, $str, $expected, $convmap, $encoding) { | ||
$result = mb_decode_numericentity($str, $convmap, $encoding); | ||
echo $desc, ": ", bin2hex($str), " => ", bin2hex($result); | ||
if ($result === $expected) | ||
echo " (Good)\n"; | ||
else | ||
echo " (BAD; expected ", bin2hex($expected), ")\n"; | ||
} | ||
|
||
$ucs4_test1 = mb_convert_encoding("�A", 'UCS-4BE', 'ASCII'); | ||
testNonAscii("Starting entity immediately after valid decimal entity which is just within maximum length", $ucs4_test1, "\x3B\x9A\xCA\x00\x00\x00\x00A", [0, 0xFFFFFFFF, 0, 0xFFFFFFFF], 'UCS-4BE'); | ||
$ucs4_test2 = mb_convert_encoding("�A", 'UCS-4BE', 'ASCII'); | ||
testNonAscii("Starting entity immediately after valid hex entity which is just within maximum length", $ucs4_test2, "\x11\x11\x11\x11\x00\x00\x00A", [0, 0xFFFFFFFF, 0, 0xFFFFFFFF], 'UCS-4BE'); | ||
|
||
test("Starting entity immediately after too-big decimal entity", "�A", "�A", [0, 0xFFFFFFFF, 0, 0xFFFFFFFF], 'ASCII'); | ||
|
||
// If the numeric entity decodes to 0xFFFFFFFF, that should be passed through | ||
// Originally, the new implementation of mb_decode_numericentity used -1 as a marker indicating | ||
// that the entity could not be successfully decoded, so if the entity decoded successfully to | ||
// 0xFFFFFFFF (-1), it would be treated as an invalid entity | ||
test("Regression test (entity which decodes to 0xFFFFFFFF)", "", "?", [0xFFFFFF86, 0xFFFFFFFF, 0xF, 0xFC015448], 'HZ'); | ||
|
||
// With the legacy conversion filters, a trailing & could be truncated by mb_decode_numericentity, | ||
// because some text encodings did not properly invoke the next flush function in the chain | ||
test("Regression test (truncation of successive & with JIS encoding)", "&&&", "&&&", [0x20FF37FF, 0x7202F569, 0xC4090023, 0xF160], "JIS"); | ||
|
||
?> | ||
--EXPECT-- | ||
Starting entity immediately after valid decimal entity which is just within maximum length: 000000260000002300000031000000300000003000000030000000300000003000000030000000300000003000000030000000260000002300000036000000350000003b => 3b9aca0000000041 (Good) | ||
Starting entity immediately after valid hex entity which is just within maximum length: 0000002600000023000000780000003100000031000000310000003100000031000000310000003100000031000000260000002300000036000000350000003b => 1111111100000041 (Good) | ||
Starting entity immediately after too-big decimal entity: string(17) "�A" => string(13) "�A" (Good) | ||
Regression test (entity which decodes to 0xFFFFFFFF): string(5) "" => string(1) "?" (Good) | ||
Regression test (truncation of successive & with JIS encoding): string(3) "&&&" => string(3) "&&&" (Good) |
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
16 changes: 16 additions & 0 deletions
16
ext/mbstring/tests/mb_encode_numericentity_large_ints.phpt
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,16 @@ | ||
--TEST-- | ||
mb_encode_numericentity() with 0xFFFFFFFF in conversion map | ||
--EXTENSIONS-- | ||
mbstring | ||
--SKIPIF-- | ||
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> | ||
--FILE-- | ||
<?php | ||
|
||
// Regression test; the old implementation could only emit hexadecimal entities with about 5 digits | ||
$convmap = [0xffffffff, 0xffffffff, 0x540a0af7, 0x5a485054]; | ||
echo "13: " . mb_encode_numericentity("\xFF", $convmap, "ASCII", true) . "\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
13: � |