1--TEST--
2htmlentities() / htmlspecialchars() ENT_DISALLOWED with entities and no double encode
3--FILE--
4<?php
5$tests = array(
6    "&#0;", //C0
7    "&#1;",
8    "&#x09;",
9    "&#x0A;",
10    "&#x0B;",
11    "&#x0C;",
12    "&#x0D;", //note that HTML5 is unique in that it forbids this entity, but allows a literal U+0D
13    "&#x0E;",
14    "&#x1F;",
15    "&#x20;", //allowed always
16    "&#x7F;", //DEL
17    "&#x80;", //C1
18    "&#x9F;",
19    "&#xA0;", //allowed always
20    "&#xD7FF;", //surrogates
21    "&#xD800;",
22    "&#xDFFF;",
23    "&#xE000;", //allowed always
24    "&#xFFFE;", //nonchar
25    "&#xFFFF;",
26    "&#xFDCF;", //allowed always
27    "&#xFDD0;", //nonchar
28    "&#xFDEF;",
29    "&#xFDF0;", //allowed always
30    "&#x2FFFE;", //nonchar
31    "&#x2FFFF;",
32    "&#x110000;", //bad reference
33);
34
35function test($flag, $flag2=ENT_DISALLOWED, $charset="UTF-8") {
36    global $tests;
37    $i = -1;
38    error_reporting(-1 & ~E_STRICT);
39    foreach ($tests as $test) {
40        $i++;
41        $a = htmlentities($test, $flag | $flag2, $charset, FALSE);
42        $b = htmlspecialchars($test, $flag | $flag2, $charset, FALSE);
43
44        if ($a == $b)
45            echo sprintf("%s\t%s", $test, $a==$test?"NOT CHANGED":"CHANGED"), "\n";
46        else
47            echo sprintf("%s\tCHANGED (%s, %s)", $test, $a, $b), "\n";
48    }
49    error_reporting(-1);
50}
51
52echo "*** Testing HTML 4.01 ***\n";
53
54test(ENT_HTML401);
55
56echo "\n*** Testing XHTML 1.0 ***\n";
57
58test(ENT_XHTML);
59
60echo "\n*** Testing HTML 5 ***\n";
61
62test(ENT_HTML5);
63
64echo "\n*** Testing XML 1.0 ***\n";
65
66test(ENT_XML1);
67
68echo "\n*** Testing 5 without the flag ***\n";
69
70test(ENT_HTML5, 0);
71
72echo "\n*** Testing HTML 5 with another single-byte encoding ***\n";
73
74test(ENT_HTML5, ENT_DISALLOWED, "Windows-1251");
75
76echo "\n*** Testing HTML 5 with another multibyte-byte encoding ***\n";
77
78test(ENT_HTML5, ENT_DISALLOWED, "SJIS");
79
80?>
81--EXPECT--
82*** Testing HTML 4.01 ***
83&#0;	NOT CHANGED
84&#1;	NOT CHANGED
85&#x09;	NOT CHANGED
86&#x0A;	NOT CHANGED
87&#x0B;	NOT CHANGED
88&#x0C;	NOT CHANGED
89&#x0D;	NOT CHANGED
90&#x0E;	NOT CHANGED
91&#x1F;	NOT CHANGED
92&#x20;	NOT CHANGED
93&#x7F;	NOT CHANGED
94&#x80;	NOT CHANGED
95&#x9F;	NOT CHANGED
96&#xA0;	NOT CHANGED
97&#xD7FF;	NOT CHANGED
98&#xD800;	NOT CHANGED
99&#xDFFF;	NOT CHANGED
100&#xE000;	NOT CHANGED
101&#xFFFE;	NOT CHANGED
102&#xFFFF;	NOT CHANGED
103&#xFDCF;	NOT CHANGED
104&#xFDD0;	NOT CHANGED
105&#xFDEF;	NOT CHANGED
106&#xFDF0;	NOT CHANGED
107&#x2FFFE;	NOT CHANGED
108&#x2FFFF;	NOT CHANGED
109&#x110000;	CHANGED
110
111*** Testing XHTML 1.0 ***
112&#0;	CHANGED
113&#1;	CHANGED
114&#x09;	NOT CHANGED
115&#x0A;	NOT CHANGED
116&#x0B;	CHANGED
117&#x0C;	CHANGED
118&#x0D;	NOT CHANGED
119&#x0E;	CHANGED
120&#x1F;	CHANGED
121&#x20;	NOT CHANGED
122&#x7F;	NOT CHANGED
123&#x80;	NOT CHANGED
124&#x9F;	NOT CHANGED
125&#xA0;	NOT CHANGED
126&#xD7FF;	NOT CHANGED
127&#xD800;	CHANGED
128&#xDFFF;	CHANGED
129&#xE000;	NOT CHANGED
130&#xFFFE;	CHANGED
131&#xFFFF;	CHANGED
132&#xFDCF;	NOT CHANGED
133&#xFDD0;	NOT CHANGED
134&#xFDEF;	NOT CHANGED
135&#xFDF0;	NOT CHANGED
136&#x2FFFE;	NOT CHANGED
137&#x2FFFF;	NOT CHANGED
138&#x110000;	CHANGED
139
140*** Testing HTML 5 ***
141&#0;	CHANGED (&amp;&num;0&semi;, &amp;#0;)
142&#1;	CHANGED (&amp;&num;1&semi;, &amp;#1;)
143&#x09;	NOT CHANGED
144&#x0A;	NOT CHANGED
145&#x0B;	CHANGED (&amp;&num;x0B&semi;, &amp;#x0B;)
146&#x0C;	NOT CHANGED
147&#x0D;	CHANGED (&amp;&num;x0D&semi;, &amp;#x0D;)
148&#x0E;	CHANGED (&amp;&num;x0E&semi;, &amp;#x0E;)
149&#x1F;	CHANGED (&amp;&num;x1F&semi;, &amp;#x1F;)
150&#x20;	NOT CHANGED
151&#x7F;	CHANGED (&amp;&num;x7F&semi;, &amp;#x7F;)
152&#x80;	CHANGED (&amp;&num;x80&semi;, &amp;#x80;)
153&#x9F;	CHANGED (&amp;&num;x9F&semi;, &amp;#x9F;)
154&#xA0;	NOT CHANGED
155&#xD7FF;	NOT CHANGED
156&#xD800;	NOT CHANGED
157&#xDFFF;	NOT CHANGED
158&#xE000;	NOT CHANGED
159&#xFFFE;	CHANGED (&amp;&num;xFFFE&semi;, &amp;#xFFFE;)
160&#xFFFF;	CHANGED (&amp;&num;xFFFF&semi;, &amp;#xFFFF;)
161&#xFDCF;	NOT CHANGED
162&#xFDD0;	CHANGED (&amp;&num;xFDD0&semi;, &amp;#xFDD0;)
163&#xFDEF;	CHANGED (&amp;&num;xFDEF&semi;, &amp;#xFDEF;)
164&#xFDF0;	NOT CHANGED
165&#x2FFFE;	CHANGED (&amp;&num;x2FFFE&semi;, &amp;#x2FFFE;)
166&#x2FFFF;	CHANGED (&amp;&num;x2FFFF&semi;, &amp;#x2FFFF;)
167&#x110000;	CHANGED (&amp;&num;x110000&semi;, &amp;#x110000;)
168
169*** Testing XML 1.0 ***
170&#0;	CHANGED
171&#1;	CHANGED
172&#x09;	NOT CHANGED
173&#x0A;	NOT CHANGED
174&#x0B;	CHANGED
175&#x0C;	CHANGED
176&#x0D;	NOT CHANGED
177&#x0E;	CHANGED
178&#x1F;	CHANGED
179&#x20;	NOT CHANGED
180&#x7F;	NOT CHANGED
181&#x80;	NOT CHANGED
182&#x9F;	NOT CHANGED
183&#xA0;	NOT CHANGED
184&#xD7FF;	NOT CHANGED
185&#xD800;	CHANGED
186&#xDFFF;	CHANGED
187&#xE000;	NOT CHANGED
188&#xFFFE;	CHANGED
189&#xFFFF;	CHANGED
190&#xFDCF;	NOT CHANGED
191&#xFDD0;	NOT CHANGED
192&#xFDEF;	NOT CHANGED
193&#xFDF0;	NOT CHANGED
194&#x2FFFE;	NOT CHANGED
195&#x2FFFF;	NOT CHANGED
196&#x110000;	CHANGED
197
198*** Testing 5 without the flag ***
199&#0;	NOT CHANGED
200&#1;	NOT CHANGED
201&#x09;	NOT CHANGED
202&#x0A;	NOT CHANGED
203&#x0B;	NOT CHANGED
204&#x0C;	NOT CHANGED
205&#x0D;	NOT CHANGED
206&#x0E;	NOT CHANGED
207&#x1F;	NOT CHANGED
208&#x20;	NOT CHANGED
209&#x7F;	NOT CHANGED
210&#x80;	NOT CHANGED
211&#x9F;	NOT CHANGED
212&#xA0;	NOT CHANGED
213&#xD7FF;	NOT CHANGED
214&#xD800;	NOT CHANGED
215&#xDFFF;	NOT CHANGED
216&#xE000;	NOT CHANGED
217&#xFFFE;	NOT CHANGED
218&#xFFFF;	NOT CHANGED
219&#xFDCF;	NOT CHANGED
220&#xFDD0;	NOT CHANGED
221&#xFDEF;	NOT CHANGED
222&#xFDF0;	NOT CHANGED
223&#x2FFFE;	NOT CHANGED
224&#x2FFFF;	NOT CHANGED
225&#x110000;	CHANGED (&amp;&num;x110000&semi;, &amp;#x110000;)
226
227*** Testing HTML 5 with another single-byte encoding ***
228&#0;	CHANGED (&amp;&num;0&semi;, &amp;#0;)
229&#1;	CHANGED (&amp;&num;1&semi;, &amp;#1;)
230&#x09;	NOT CHANGED
231&#x0A;	NOT CHANGED
232&#x0B;	CHANGED (&amp;&num;x0B&semi;, &amp;#x0B;)
233&#x0C;	NOT CHANGED
234&#x0D;	CHANGED (&amp;&num;x0D&semi;, &amp;#x0D;)
235&#x0E;	CHANGED (&amp;&num;x0E&semi;, &amp;#x0E;)
236&#x1F;	CHANGED (&amp;&num;x1F&semi;, &amp;#x1F;)
237&#x20;	NOT CHANGED
238&#x7F;	CHANGED (&amp;&num;x7F&semi;, &amp;#x7F;)
239&#x80;	CHANGED (&amp;&num;x80&semi;, &amp;#x80;)
240&#x9F;	CHANGED (&amp;&num;x9F&semi;, &amp;#x9F;)
241&#xA0;	NOT CHANGED
242&#xD7FF;	NOT CHANGED
243&#xD800;	NOT CHANGED
244&#xDFFF;	NOT CHANGED
245&#xE000;	NOT CHANGED
246&#xFFFE;	CHANGED (&amp;&num;xFFFE&semi;, &amp;#xFFFE;)
247&#xFFFF;	CHANGED (&amp;&num;xFFFF&semi;, &amp;#xFFFF;)
248&#xFDCF;	NOT CHANGED
249&#xFDD0;	CHANGED (&amp;&num;xFDD0&semi;, &amp;#xFDD0;)
250&#xFDEF;	CHANGED (&amp;&num;xFDEF&semi;, &amp;#xFDEF;)
251&#xFDF0;	NOT CHANGED
252&#x2FFFE;	CHANGED (&amp;&num;x2FFFE&semi;, &amp;#x2FFFE;)
253&#x2FFFF;	CHANGED (&amp;&num;x2FFFF&semi;, &amp;#x2FFFF;)
254&#x110000;	CHANGED (&amp;&num;x110000&semi;, &amp;#x110000;)
255
256*** Testing HTML 5 with another multibyte-byte encoding ***
257&#0;	CHANGED
258&#1;	CHANGED
259&#x09;	NOT CHANGED
260&#x0A;	NOT CHANGED
261&#x0B;	CHANGED
262&#x0C;	NOT CHANGED
263&#x0D;	CHANGED
264&#x0E;	CHANGED
265&#x1F;	CHANGED
266&#x20;	NOT CHANGED
267&#x7F;	CHANGED
268&#x80;	CHANGED
269&#x9F;	CHANGED
270&#xA0;	NOT CHANGED
271&#xD7FF;	NOT CHANGED
272&#xD800;	NOT CHANGED
273&#xDFFF;	NOT CHANGED
274&#xE000;	NOT CHANGED
275&#xFFFE;	CHANGED
276&#xFFFF;	CHANGED
277&#xFDCF;	NOT CHANGED
278&#xFDD0;	CHANGED
279&#xFDEF;	CHANGED
280&#xFDF0;	NOT CHANGED
281&#x2FFFE;	CHANGED
282&#x2FFFF;	CHANGED
283&#x110000;	CHANGED
284