1--TEST--
2htmlentities() / htmlspecialchars() ENT_DISALLOWED charset variation
3--FILE--
4<?php
5$tests = array(
6    0x00, //C0
7    0x01,
8    0x09,
9    0x0A,
10    0x0B,
11    0x0C,
12    0x0D,
13    0x0E,
14    0x1F,
15    0x20, //allowed always
16    0x7F, //DEL
17    0x80, //C1
18    0x9F,
19    0xA0, //allowed always
20);
21
22function test($flag, $charset) {
23    global $tests;
24    $i = -1;
25    error_reporting(-1 & ~E_STRICT);
26    foreach ($tests as $test) {
27        $test = chr($test);
28        $i++;
29        $a = htmlentities($test, $flag | ENT_DISALLOWED, $charset);
30        $b = htmlspecialchars($test, $flag | ENT_DISALLOWED, $charset);
31        if ($a == "" && $b == "") { echo sprintf("%05X", $tests[$i]), ": INVALID SEQUENCE\n"; continue; }
32        echo sprintf("%05X", $tests[$i]), ": ", bin2hex($a), " ", bin2hex($b), "\n";
33    }
34    error_reporting(-1);
35}
36
37echo "*** Testing HTML 4.01/Windows-1251 ***\n";
38
39test(ENT_HTML401, "Windows-1251");
40
41echo "\n*** Testing XHTML 1.0/Windows-1251 ***\n";
42
43test(ENT_XHTML, "Windows-1251");
44
45echo "\n*** Testing HTML 5/Windows-1251 ***\n";
46
47test(ENT_HTML5, "Windows-1251");
48
49echo "\n*** Testing XML 1.0/Windows-1251 ***\n";
50
51test(ENT_XML1, "Windows-1251");
52
53echo "\n*** Testing HTML 4.01/SJIS ***\n";
54
55test(ENT_HTML401, "SJIS");
56
57echo "\n*** Testing XHTML 1.0/SJIS ***\n";
58
59test(ENT_XHTML, "SJIS");
60
61echo "\n*** Testing HTML 5/SJIS ***\n";
62
63test(ENT_HTML5, "SJIS");
64
65echo "\n*** Testing XML 1.0/SJIS ***\n";
66
67test(ENT_XML1, "SJIS");
68
69
70?>
71--EXPECT--
72*** Testing HTML 4.01/Windows-1251 ***
7300000: 262378464646443b 262378464646443b
7400001: 262378464646443b 262378464646443b
7500009: 09 09
760000A: 0a 0a
770000B: 262378464646443b 262378464646443b
780000C: 262378464646443b 262378464646443b
790000D: 0d 0d
800000E: 262378464646443b 262378464646443b
810001F: 262378464646443b 262378464646443b
8200020: 20 20
830007F: 262378464646443b 7f
8400080: 80 80
850009F: 9f 9f
86000A0: 266e6273703b a0
87
88*** Testing XHTML 1.0/Windows-1251 ***
8900000: 262378464646443b 262378464646443b
9000001: 262378464646443b 262378464646443b
9100009: 09 09
920000A: 0a 0a
930000B: 262378464646443b 262378464646443b
940000C: 262378464646443b 262378464646443b
950000D: 0d 0d
960000E: 262378464646443b 262378464646443b
970001F: 262378464646443b 262378464646443b
9800020: 20 20
990007F: 7f 7f
10000080: 80 80
1010009F: 9f 9f
102000A0: 266e6273703b a0
103
104*** Testing HTML 5/Windows-1251 ***
10500000: 262378464646443b 262378464646443b
10600001: 262378464646443b 262378464646443b
10700009: 265461623b 09
1080000A: 264e65774c696e653b 0a
1090000B: 262378464646443b 262378464646443b
1100000C: 0c 0c
1110000D: 0d 0d
1120000E: 262378464646443b 262378464646443b
1130001F: 262378464646443b 262378464646443b
11400020: 20 20
1150007F: 262378464646443b 7f
11600080: 26444a63793b 80
1170009F: 26647a63793b 9f
118000A0: 266e6273703b a0
119
120*** Testing XML 1.0/Windows-1251 ***
12100000: 262378464646443b 262378464646443b
12200001: 262378464646443b 262378464646443b
12300009: 09 09
1240000A: 0a 0a
1250000B: 262378464646443b 262378464646443b
1260000C: 262378464646443b 262378464646443b
1270000D: 0d 0d
1280000E: 262378464646443b 262378464646443b
1290001F: 262378464646443b 262378464646443b
13000020: 20 20
1310007F: 7f 7f
13200080: 80 80
1330009F: 9f 9f
134000A0: a0 a0
135
136*** Testing HTML 4.01/SJIS ***
13700000: 262378464646443b 262378464646443b
13800001: 262378464646443b 262378464646443b
13900009: 09 09
1400000A: 0a 0a
1410000B: 262378464646443b 262378464646443b
1420000C: 262378464646443b 262378464646443b
1430000D: 0d 0d
1440000E: 262378464646443b 262378464646443b
1450001F: 262378464646443b 262378464646443b
14600020: 20 20
1470007F: 7f 7f
14800080: INVALID SEQUENCE
1490009F: INVALID SEQUENCE
150000A0: INVALID SEQUENCE
151
152*** Testing XHTML 1.0/SJIS ***
15300000: 262378464646443b 262378464646443b
15400001: 262378464646443b 262378464646443b
15500009: 09 09
1560000A: 0a 0a
1570000B: 262378464646443b 262378464646443b
1580000C: 262378464646443b 262378464646443b
1590000D: 0d 0d
1600000E: 262378464646443b 262378464646443b
1610001F: 262378464646443b 262378464646443b
16200020: 20 20
1630007F: 7f 7f
16400080: INVALID SEQUENCE
1650009F: INVALID SEQUENCE
166000A0: INVALID SEQUENCE
167
168*** Testing HTML 5/SJIS ***
16900000: 262378464646443b 262378464646443b
17000001: 262378464646443b 262378464646443b
17100009: 09 09
1720000A: 0a 0a
1730000B: 262378464646443b 262378464646443b
1740000C: 0c 0c
1750000D: 0d 0d
1760000E: 262378464646443b 262378464646443b
1770001F: 262378464646443b 262378464646443b
17800020: 20 20
1790007F: 7f 7f
18000080: INVALID SEQUENCE
1810009F: INVALID SEQUENCE
182000A0: INVALID SEQUENCE
183
184*** Testing XML 1.0/SJIS ***
18500000: 262378464646443b 262378464646443b
18600001: 262378464646443b 262378464646443b
18700009: 09 09
1880000A: 0a 0a
1890000B: 262378464646443b 262378464646443b
1900000C: 262378464646443b 262378464646443b
1910000D: 0d 0d
1920000E: 262378464646443b 262378464646443b
1930001F: 262378464646443b 262378464646443b
19400020: 20 20
1950007F: 7f 7f
19600080: INVALID SEQUENCE
1970009F: INVALID SEQUENCE
198000A0: INVALID SEQUENCE
199