1--TEST--
2html_entity_decode: Do not decode numerical entities that refer to non-SGML or otherwise disallowed chars
3--FILE--
4<?php
5
6$tests = array(
7    "&#0;", //C0
8    "&#1;",
9    "&#x09;",
10    "&#x0A;",
11    "&#x0B;",
12    "&#x0C;",
13    "&#x0D;", //note that HTML5 is unique in that it forbids this entity, but allows a literal U+0D
14    "&#x0E;",
15    "&#x1F;",
16    "&#x20;", //allowed always
17    "&#x27;", //single quote, depends on flags
18    "&#x7F;", //DEL
19    "&#x80;", //C1
20    "&#x9F;",
21    "&#xA0;", //allowed always
22    "&#xD7FF;", //surrogates
23    "&#xD800;",
24    "&#xDFFF;",
25    "&#xE000;", //allowed always
26    "&#xFFFE;", //nonchar
27    "&#xFFFF;",
28    "&#xFDCF;", //allowed always
29    "&#xFDD0;", //nonchar
30    "&#xFDEF;",
31    "&#xFDF0;", //allowed always
32    "&#x2FFFE;", //nonchar
33    "&#x2FFFF;",
34);
35
36echo "*** HTML 4.01  ***\n";
37
38foreach ($tests as $t) {
39    $dec = html_entity_decode($t, ENT_QUOTES | ENT_HTML401, "UTF-8");
40    if ($t == $dec) {
41        echo "$t\tNOT DECODED\n";
42    } else {
43        echo "$t\tDECODED\n";
44    }
45}
46
47echo "\n*** XHTML 1.0  ***\n";
48
49foreach ($tests as $t) {
50    $dec = html_entity_decode($t, ENT_QUOTES | ENT_XHTML, "UTF-8");
51    if ($t == $dec) {
52        echo "$t\tNOT DECODED\n";
53    } else {
54        echo "$t\tDECODED\n";
55    }
56}
57
58echo "\n*** HTML5  ***\n";
59
60foreach ($tests as $t) {
61    $dec = html_entity_decode($t, ENT_QUOTES | ENT_HTML5, "UTF-8");
62    if ($t == $dec) {
63        echo "$t\tNOT DECODED\n";
64    } else {
65        echo "$t\tDECODED\n";
66    }
67}
68
69echo "\n*** XML 1.0  ***\n";
70
71foreach ($tests as $t) {
72    $dec = html_entity_decode($t, ENT_QUOTES | ENT_XML1, "UTF-8");
73    if ($t == $dec) {
74        echo "$t\tNOT DECODED\n";
75    } else {
76        echo "$t\tDECODED\n";
77    }
78}
79
80echo "\n*** Default options ***\n";
81
82foreach ($tests as $t) {
83    $dec = html_entity_decode($t);
84    if ($t == $dec) {
85        echo "$t\tNOT DECODED\n";
86    } else {
87        echo "$t\tDECODED\n";
88    }
89}
90
91echo "\nDone.\n";
92--EXPECT--
93*** HTML 4.01  ***
94&#0;	NOT DECODED
95&#1;	NOT DECODED
96&#x09;	DECODED
97&#x0A;	DECODED
98&#x0B;	NOT DECODED
99&#x0C;	NOT DECODED
100&#x0D;	DECODED
101&#x0E;	NOT DECODED
102&#x1F;	NOT DECODED
103&#x20;	DECODED
104&#x27;	DECODED
105&#x7F;	NOT DECODED
106&#x80;	NOT DECODED
107&#x9F;	NOT DECODED
108&#xA0;	DECODED
109&#xD7FF;	DECODED
110&#xD800;	NOT DECODED
111&#xDFFF;	NOT DECODED
112&#xE000;	DECODED
113&#xFFFE;	DECODED
114&#xFFFF;	DECODED
115&#xFDCF;	DECODED
116&#xFDD0;	DECODED
117&#xFDEF;	DECODED
118&#xFDF0;	DECODED
119&#x2FFFE;	DECODED
120&#x2FFFF;	DECODED
121
122*** XHTML 1.0  ***
123&#0;	NOT DECODED
124&#1;	NOT DECODED
125&#x09;	DECODED
126&#x0A;	DECODED
127&#x0B;	NOT DECODED
128&#x0C;	NOT DECODED
129&#x0D;	DECODED
130&#x0E;	NOT DECODED
131&#x1F;	NOT DECODED
132&#x20;	DECODED
133&#x27;	DECODED
134&#x7F;	DECODED
135&#x80;	DECODED
136&#x9F;	DECODED
137&#xA0;	DECODED
138&#xD7FF;	DECODED
139&#xD800;	NOT DECODED
140&#xDFFF;	NOT DECODED
141&#xE000;	DECODED
142&#xFFFE;	NOT DECODED
143&#xFFFF;	NOT DECODED
144&#xFDCF;	DECODED
145&#xFDD0;	DECODED
146&#xFDEF;	DECODED
147&#xFDF0;	DECODED
148&#x2FFFE;	DECODED
149&#x2FFFF;	DECODED
150
151*** HTML5  ***
152&#0;	NOT DECODED
153&#1;	NOT DECODED
154&#x09;	DECODED
155&#x0A;	DECODED
156&#x0B;	NOT DECODED
157&#x0C;	DECODED
158&#x0D;	NOT DECODED
159&#x0E;	NOT DECODED
160&#x1F;	NOT DECODED
161&#x20;	DECODED
162&#x27;	DECODED
163&#x7F;	NOT DECODED
164&#x80;	NOT DECODED
165&#x9F;	NOT DECODED
166&#xA0;	DECODED
167&#xD7FF;	DECODED
168&#xD800;	NOT DECODED
169&#xDFFF;	NOT DECODED
170&#xE000;	DECODED
171&#xFFFE;	NOT DECODED
172&#xFFFF;	NOT DECODED
173&#xFDCF;	DECODED
174&#xFDD0;	NOT DECODED
175&#xFDEF;	NOT DECODED
176&#xFDF0;	DECODED
177&#x2FFFE;	NOT DECODED
178&#x2FFFF;	NOT DECODED
179
180*** XML 1.0  ***
181&#0;	NOT DECODED
182&#1;	NOT DECODED
183&#x09;	DECODED
184&#x0A;	DECODED
185&#x0B;	NOT DECODED
186&#x0C;	NOT DECODED
187&#x0D;	DECODED
188&#x0E;	NOT DECODED
189&#x1F;	NOT DECODED
190&#x20;	DECODED
191&#x27;	DECODED
192&#x7F;	DECODED
193&#x80;	DECODED
194&#x9F;	DECODED
195&#xA0;	DECODED
196&#xD7FF;	DECODED
197&#xD800;	NOT DECODED
198&#xDFFF;	NOT DECODED
199&#xE000;	DECODED
200&#xFFFE;	NOT DECODED
201&#xFFFF;	NOT DECODED
202&#xFDCF;	DECODED
203&#xFDD0;	DECODED
204&#xFDEF;	DECODED
205&#xFDF0;	DECODED
206&#x2FFFE;	DECODED
207&#x2FFFF;	DECODED
208
209*** Default options ***
210&#0;	NOT DECODED
211&#1;	NOT DECODED
212&#x09;	DECODED
213&#x0A;	DECODED
214&#x0B;	NOT DECODED
215&#x0C;	NOT DECODED
216&#x0D;	DECODED
217&#x0E;	NOT DECODED
218&#x1F;	NOT DECODED
219&#x20;	DECODED
220&#x27;	NOT DECODED
221&#x7F;	NOT DECODED
222&#x80;	NOT DECODED
223&#x9F;	NOT DECODED
224&#xA0;	DECODED
225&#xD7FF;	DECODED
226&#xD800;	NOT DECODED
227&#xDFFF;	NOT DECODED
228&#xE000;	DECODED
229&#xFFFE;	DECODED
230&#xFFFF;	DECODED
231&#xFDCF;	DECODED
232&#xFDD0;	DECODED
233&#xFDEF;	DECODED
234&#xFDF0;	DECODED
235&#x2FFFE;	DECODED
236&#x2FFFF;	DECODED
237
238Done.
239