1--TEST-- 2htmlentities() / htmlspecialchars() ENT_DISALLOWED 3--FILE-- 4<?php 5function codepoint_to_utf8($k) { 6 if ($k < 0x80) { 7 $retval = pack('C', $k); 8 } else if ($k < 0x800) { 9 $retval = pack('C2', 10 0xc0 | ($k >> 6), 11 0x80 | ($k & 0x3f)); 12 } else if ($k < 0x10000) { 13 $retval = pack('C3', 14 0xe0 | ($k >> 12), 15 0x80 | (($k >> 6) & 0x3f), 16 0x80 | ($k & 0x3f)); 17 } else { 18 $retval = pack('C4', 19 0xf0 | ($k >> 18), 20 0x80 | (($k >> 12) & 0x3f), 21 0x80 | (($k >> 6) & 0x3f), 22 0x80 | ($k & 0x3f)); 23 } 24 return $retval; 25} 26 27$tests = array( 28 0x00, //C0 29 0x01, 30 0x09, 31 0x0A, 32 0x0B, 33 0x0C, 34 0x0D, 35 0x0E, 36 0x1F, 37 0x20, //allowed always 38 0x7F, //DEL 39 0x80, //C1 40 0x9F, 41 0xA0, //allowed always 42 0xD7FF, //surrogates 43 0xD800, 44 0xDFFF, 45 0xE000, //allowed always 46 0xFFFE, //nonchar 47 0xFFFF, 48 0xFDCF, //allowed always 49 0xFDD0, //nonchar 50 0xFDEF, 51 0xFDF0, //allowed always 52 0x2FFFE, //nonchar 53 0x2FFFF, 54); 55$tests2 = array_map('codepoint_to_utf8', $tests); 56 57$subchr = codepoint_to_utf8(0xFFFD); 58 59function test($flag) { 60 global $tests, $tests2; 61 $i = -1; 62 foreach ($tests2 as $test) { 63 $i++; 64 $a = htmlentities($test, $flag | ENT_DISALLOWED, "UTF-8"); 65 $b = htmlspecialchars($test, $flag | ENT_DISALLOWED, "UTF-8"); 66 if ($a == "" && $b == "") { echo sprintf("%05X", $tests[$i]), ": INVALID SEQUENCE\n"; continue; } 67 echo sprintf("%05X", $tests[$i]), ": ", bin2hex($a), " ", bin2hex($b), "\n"; 68 } 69} 70 71echo "*** Testing HTML 4.01 ***\n"; 72 73test(ENT_HTML401); 74 75echo "\n*** Testing XHTML 1.0 ***\n"; 76 77test(ENT_XHTML); 78 79echo "\n*** Testing HTML 5 ***\n"; 80 81test(ENT_HTML5); 82 83echo "\n*** Testing XML 1.0 ***\n"; 84 85test(ENT_XML1); 86 87?> 88--EXPECT-- 89*** Testing HTML 4.01 *** 9000000: efbfbd efbfbd 9100001: efbfbd efbfbd 9200009: 09 09 930000A: 0a 0a 940000B: efbfbd efbfbd 950000C: efbfbd efbfbd 960000D: 0d 0d 970000E: efbfbd efbfbd 980001F: efbfbd efbfbd 9900020: 20 20 1000007F: efbfbd efbfbd 10100080: efbfbd efbfbd 1020009F: efbfbd efbfbd 103000A0: 266e6273703b c2a0 1040D7FF: ed9fbf ed9fbf 1050D800: INVALID SEQUENCE 1060DFFF: INVALID SEQUENCE 1070E000: ee8080 ee8080 1080FFFE: efbfbe efbfbe 1090FFFF: efbfbf efbfbf 1100FDCF: efb78f efb78f 1110FDD0: efb790 efb790 1120FDEF: efb7af efb7af 1130FDF0: efb7b0 efb7b0 1142FFFE: f0afbfbe f0afbfbe 1152FFFF: f0afbfbf f0afbfbf 116 117*** Testing XHTML 1.0 *** 11800000: efbfbd efbfbd 11900001: efbfbd efbfbd 12000009: 09 09 1210000A: 0a 0a 1220000B: efbfbd efbfbd 1230000C: efbfbd efbfbd 1240000D: 0d 0d 1250000E: efbfbd efbfbd 1260001F: efbfbd efbfbd 12700020: 20 20 1280007F: 7f 7f 12900080: c280 c280 1300009F: c29f c29f 131000A0: 266e6273703b c2a0 1320D7FF: ed9fbf ed9fbf 1330D800: INVALID SEQUENCE 1340DFFF: INVALID SEQUENCE 1350E000: ee8080 ee8080 1360FFFE: efbfbd efbfbd 1370FFFF: efbfbd efbfbd 1380FDCF: efb78f efb78f 1390FDD0: efb790 efb790 1400FDEF: efb7af efb7af 1410FDF0: efb7b0 efb7b0 1422FFFE: f0afbfbe f0afbfbe 1432FFFF: f0afbfbf f0afbfbf 144 145*** Testing HTML 5 *** 14600000: efbfbd efbfbd 14700001: efbfbd efbfbd 14800009: 265461623b 09 1490000A: 264e65774c696e653b 0a 1500000B: efbfbd efbfbd 1510000C: 0c 0c 1520000D: 0d 0d 1530000E: efbfbd efbfbd 1540001F: efbfbd efbfbd 15500020: 20 20 1560007F: efbfbd efbfbd 15700080: efbfbd efbfbd 1580009F: efbfbd efbfbd 159000A0: 266e6273703b c2a0 1600D7FF: ed9fbf ed9fbf 1610D800: INVALID SEQUENCE 1620DFFF: INVALID SEQUENCE 1630E000: ee8080 ee8080 1640FFFE: efbfbd efbfbd 1650FFFF: efbfbd efbfbd 1660FDCF: efb78f efb78f 1670FDD0: efbfbd efbfbd 1680FDEF: efbfbd efbfbd 1690FDF0: efb7b0 efb7b0 1702FFFE: efbfbd efbfbd 1712FFFF: efbfbd efbfbd 172 173*** Testing XML 1.0 *** 17400000: efbfbd efbfbd 17500001: efbfbd efbfbd 17600009: 09 09 1770000A: 0a 0a 1780000B: efbfbd efbfbd 1790000C: efbfbd efbfbd 1800000D: 0d 0d 1810000E: efbfbd efbfbd 1820001F: efbfbd efbfbd 18300020: 20 20 1840007F: 7f 7f 18500080: c280 c280 1860009F: c29f c29f 187000A0: c2a0 c2a0 1880D7FF: ed9fbf ed9fbf 1890D800: INVALID SEQUENCE 1900DFFF: INVALID SEQUENCE 1910E000: ee8080 ee8080 1920FFFE: efbfbd efbfbd 1930FFFF: efbfbd efbfbd 1940FDCF: efb78f efb78f 1950FDD0: efb790 efb790 1960FDEF: efb7af efb7af 1970FDF0: efb7b0 efb7b0 1982FFFE: f0afbfbe f0afbfbe 1992FFFF: f0afbfbf f0afbfbf 200