1--TEST-- 2mb_decode_numericentity() with 0xFFFFFFFF in conversion map 3--EXTENSIONS-- 4mbstring 5--SKIPIF-- 6<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> 7--FILE-- 8<?php 9 10function varDumpToString($var) 11{ 12 ob_start(); 13 var_dump($var); 14 return trim(ob_get_clean()); 15} 16 17function test($desc, $str, $expected, $convmap, $encoding) { 18 $result = mb_decode_numericentity($str, $convmap, $encoding); 19 echo $desc, ": ", varDumpToString($str), " => ", varDumpToString($result); 20 if ($result === $expected) 21 echo " (Good)\n"; 22 else 23 echo " (BAD; expected ", varDumpToString($expected), ")\n"; 24} 25 26function testNonAscii($desc, $str, $expected, $convmap, $encoding) { 27 $result = mb_decode_numericentity($str, $convmap, $encoding); 28 echo $desc, ": ", bin2hex($str), " => ", bin2hex($result); 29 if ($result === $expected) 30 echo " (Good)\n"; 31 else 32 echo " (BAD; expected ", bin2hex($expected), ")\n"; 33} 34 35$ucs4_test1 = mb_convert_encoding("�A", 'UCS-4BE', 'ASCII'); 36testNonAscii("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'); 37$ucs4_test2 = mb_convert_encoding("�A", 'UCS-4BE', 'ASCII'); 38testNonAscii("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'); 39 40test("Starting entity immediately after too-big decimal entity", "�A", "�A", [0, 0xFFFFFFFF, 0, 0xFFFFFFFF], 'ASCII'); 41 42// If the numeric entity decodes to 0xFFFFFFFF, that should be passed through 43// Originally, the new implementation of mb_decode_numericentity used -1 as a marker indicating 44// that the entity could not be successfully decoded, so if the entity decoded successfully to 45// 0xFFFFFFFF (-1), it would be treated as an invalid entity 46test("Regression test (entity which decodes to 0xFFFFFFFF)", "", "?", [0xFFFFFF86, 0xFFFFFFFF, 0xF, 0xFC015448], 'HZ'); 47 48// With the legacy conversion filters, a trailing & could be truncated by mb_decode_numericentity, 49// because some text encodings did not properly invoke the next flush function in the chain 50test("Regression test (truncation of successive & with JIS encoding)", "&&&", "&&&", [0x20FF37FF, 0x7202F569, 0xC4090023, 0xF160], "JIS"); 51 52// Previously, signed arithmetic was used on convmap entries 53test("Regression test (convmap entries are now treated as unsigned)", ",", "?,", [0x22FFFF11, 0xBF111189, 0x67726511, 0x1161E719], "ASCII"); 54 55?> 56--EXPECT-- 57Starting entity immediately after valid decimal entity which is just within maximum length: 000000260000002300000031000000300000003000000030000000300000003000000030000000300000003000000030000000260000002300000036000000350000003b => 3b9aca0000000041 (Good) 58Starting entity immediately after valid hex entity which is just within maximum length: 0000002600000023000000780000003100000031000000310000003100000031000000310000003100000031000000260000002300000036000000350000003b => 1111111100000041 (Good) 59Starting entity immediately after too-big decimal entity: string(17) "�A" => string(13) "�A" (Good) 60Regression test (entity which decodes to 0xFFFFFFFF): string(5) "" => string(1) "?" (Good) 61Regression test (truncation of successive & with JIS encoding): string(3) "&&&" => string(3) "&&&" (Good) 62Regression test (convmap entries are now treated as unsigned): string(4) "," => string(2) "?," (Good) 63