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?>
93--EXPECT--
94*** HTML 4.01  ***
95&#0;	NOT DECODED
96&#1;	NOT DECODED
97&#x09;	DECODED
98&#x0A;	DECODED
99&#x0B;	NOT DECODED
100&#x0C;	NOT DECODED
101&#x0D;	DECODED
102&#x0E;	NOT DECODED
103&#x1F;	NOT DECODED
104&#x20;	DECODED
105&#x27;	DECODED
106&#x7F;	NOT DECODED
107&#x80;	NOT DECODED
108&#x9F;	NOT DECODED
109&#xA0;	DECODED
110&#xD7FF;	DECODED
111&#xD800;	NOT DECODED
112&#xDFFF;	NOT DECODED
113&#xE000;	DECODED
114&#xFFFE;	DECODED
115&#xFFFF;	DECODED
116&#xFDCF;	DECODED
117&#xFDD0;	DECODED
118&#xFDEF;	DECODED
119&#xFDF0;	DECODED
120&#x2FFFE;	DECODED
121&#x2FFFF;	DECODED
122
123*** XHTML 1.0  ***
124&#0;	NOT DECODED
125&#1;	NOT DECODED
126&#x09;	DECODED
127&#x0A;	DECODED
128&#x0B;	NOT DECODED
129&#x0C;	NOT DECODED
130&#x0D;	DECODED
131&#x0E;	NOT DECODED
132&#x1F;	NOT DECODED
133&#x20;	DECODED
134&#x27;	DECODED
135&#x7F;	DECODED
136&#x80;	DECODED
137&#x9F;	DECODED
138&#xA0;	DECODED
139&#xD7FF;	DECODED
140&#xD800;	NOT DECODED
141&#xDFFF;	NOT DECODED
142&#xE000;	DECODED
143&#xFFFE;	NOT DECODED
144&#xFFFF;	NOT DECODED
145&#xFDCF;	DECODED
146&#xFDD0;	DECODED
147&#xFDEF;	DECODED
148&#xFDF0;	DECODED
149&#x2FFFE;	DECODED
150&#x2FFFF;	DECODED
151
152*** HTML5  ***
153&#0;	NOT DECODED
154&#1;	NOT DECODED
155&#x09;	DECODED
156&#x0A;	DECODED
157&#x0B;	NOT DECODED
158&#x0C;	DECODED
159&#x0D;	NOT DECODED
160&#x0E;	NOT DECODED
161&#x1F;	NOT DECODED
162&#x20;	DECODED
163&#x27;	DECODED
164&#x7F;	NOT DECODED
165&#x80;	NOT DECODED
166&#x9F;	NOT DECODED
167&#xA0;	DECODED
168&#xD7FF;	DECODED
169&#xD800;	NOT DECODED
170&#xDFFF;	NOT DECODED
171&#xE000;	DECODED
172&#xFFFE;	NOT DECODED
173&#xFFFF;	NOT DECODED
174&#xFDCF;	DECODED
175&#xFDD0;	NOT DECODED
176&#xFDEF;	NOT DECODED
177&#xFDF0;	DECODED
178&#x2FFFE;	NOT DECODED
179&#x2FFFF;	NOT DECODED
180
181*** XML 1.0  ***
182&#0;	NOT DECODED
183&#1;	NOT DECODED
184&#x09;	DECODED
185&#x0A;	DECODED
186&#x0B;	NOT DECODED
187&#x0C;	NOT DECODED
188&#x0D;	DECODED
189&#x0E;	NOT DECODED
190&#x1F;	NOT DECODED
191&#x20;	DECODED
192&#x27;	DECODED
193&#x7F;	DECODED
194&#x80;	DECODED
195&#x9F;	DECODED
196&#xA0;	DECODED
197&#xD7FF;	DECODED
198&#xD800;	NOT DECODED
199&#xDFFF;	NOT DECODED
200&#xE000;	DECODED
201&#xFFFE;	NOT DECODED
202&#xFFFF;	NOT DECODED
203&#xFDCF;	DECODED
204&#xFDD0;	DECODED
205&#xFDEF;	DECODED
206&#xFDF0;	DECODED
207&#x2FFFE;	DECODED
208&#x2FFFF;	DECODED
209
210*** Default options ***
211&#0;	NOT DECODED
212&#1;	NOT DECODED
213&#x09;	DECODED
214&#x0A;	DECODED
215&#x0B;	NOT DECODED
216&#x0C;	NOT DECODED
217&#x0D;	DECODED
218&#x0E;	NOT DECODED
219&#x1F;	NOT DECODED
220&#x20;	DECODED
221&#x27;	DECODED
222&#x7F;	NOT DECODED
223&#x80;	NOT DECODED
224&#x9F;	NOT DECODED
225&#xA0;	DECODED
226&#xD7FF;	DECODED
227&#xD800;	NOT DECODED
228&#xDFFF;	NOT DECODED
229&#xE000;	DECODED
230&#xFFFE;	DECODED
231&#xFFFF;	DECODED
232&#xFDCF;	DECODED
233&#xFDD0;	DECODED
234&#xFDEF;	DECODED
235&#xFDF0;	DECODED
236&#x2FFFE;	DECODED
237&#x2FFFF;	DECODED
238
239Done.
240