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    "&#x7F;", //DEL
18    "&#x80;", //C1
19    "&#x9F;",
20    "&#xA0;", //allowed always
21    "&#xD7FF;", //surrogates
22    "&#xD800;",
23    "&#xDFFF;",
24    "&#xE000;", //allowed always
25    "&#xFFFE;", //nonchar
26    "&#xFFFF;",
27    "&#xFDCF;", //allowed always
28    "&#xFDD0;", //nonchar
29    "&#xFDEF;",
30    "&#xFDF0;", //allowed always
31    "&#x2FFFE;", //nonchar
32    "&#x2FFFF;",
33);
34
35echo "*** HTML 4.01  ***\n";
36
37foreach ($tests as $t) {
38    $dec = html_entity_decode($t, ENT_QUOTES | ENT_HTML401, "UTF-8");
39    if ($t == $dec) {
40        echo "$t\tNOT DECODED\n";
41    } else {
42        echo "$t\tDECODED\n";
43    }
44}
45
46echo "\n*** XHTML 1.0  ***\n";
47
48foreach ($tests as $t) {
49    $dec = html_entity_decode($t, ENT_QUOTES | ENT_XHTML, "UTF-8");
50    if ($t == $dec) {
51        echo "$t\tNOT DECODED\n";
52    } else {
53        echo "$t\tDECODED\n";
54    }
55}
56
57echo "\n*** HTML5  ***\n";
58
59foreach ($tests as $t) {
60    $dec = html_entity_decode($t, ENT_QUOTES | ENT_HTML5, "UTF-8");
61    if ($t == $dec) {
62        echo "$t\tNOT DECODED\n";
63    } else {
64        echo "$t\tDECODED\n";
65    }
66}
67
68echo "\n*** XML 1.0  ***\n";
69
70foreach ($tests as $t) {
71    $dec = html_entity_decode($t, ENT_QUOTES | ENT_XML1, "UTF-8");
72    if ($t == $dec) {
73        echo "$t\tNOT DECODED\n";
74    } else {
75        echo "$t\tDECODED\n";
76    }
77}
78
79echo "\nDone.\n";
80--EXPECT--
81*** HTML 4.01  ***
82&#0;	NOT DECODED
83&#1;	NOT DECODED
84&#x09;	DECODED
85&#x0A;	DECODED
86&#x0B;	NOT DECODED
87&#x0C;	NOT DECODED
88&#x0D;	DECODED
89&#x0E;	NOT DECODED
90&#x1F;	NOT DECODED
91&#x20;	DECODED
92&#x7F;	NOT DECODED
93&#x80;	NOT DECODED
94&#x9F;	NOT DECODED
95&#xA0;	DECODED
96&#xD7FF;	DECODED
97&#xD800;	NOT DECODED
98&#xDFFF;	NOT DECODED
99&#xE000;	DECODED
100&#xFFFE;	DECODED
101&#xFFFF;	DECODED
102&#xFDCF;	DECODED
103&#xFDD0;	DECODED
104&#xFDEF;	DECODED
105&#xFDF0;	DECODED
106&#x2FFFE;	DECODED
107&#x2FFFF;	DECODED
108
109*** XHTML 1.0  ***
110&#0;	NOT DECODED
111&#1;	NOT DECODED
112&#x09;	DECODED
113&#x0A;	DECODED
114&#x0B;	NOT DECODED
115&#x0C;	NOT DECODED
116&#x0D;	DECODED
117&#x0E;	NOT DECODED
118&#x1F;	NOT DECODED
119&#x20;	DECODED
120&#x7F;	DECODED
121&#x80;	DECODED
122&#x9F;	DECODED
123&#xA0;	DECODED
124&#xD7FF;	DECODED
125&#xD800;	NOT DECODED
126&#xDFFF;	NOT DECODED
127&#xE000;	DECODED
128&#xFFFE;	NOT DECODED
129&#xFFFF;	NOT DECODED
130&#xFDCF;	DECODED
131&#xFDD0;	DECODED
132&#xFDEF;	DECODED
133&#xFDF0;	DECODED
134&#x2FFFE;	DECODED
135&#x2FFFF;	DECODED
136
137*** HTML5  ***
138&#0;	NOT DECODED
139&#1;	NOT DECODED
140&#x09;	DECODED
141&#x0A;	DECODED
142&#x0B;	NOT DECODED
143&#x0C;	DECODED
144&#x0D;	NOT DECODED
145&#x0E;	NOT DECODED
146&#x1F;	NOT DECODED
147&#x20;	DECODED
148&#x7F;	NOT DECODED
149&#x80;	NOT DECODED
150&#x9F;	NOT DECODED
151&#xA0;	DECODED
152&#xD7FF;	DECODED
153&#xD800;	NOT DECODED
154&#xDFFF;	NOT DECODED
155&#xE000;	DECODED
156&#xFFFE;	NOT DECODED
157&#xFFFF;	NOT DECODED
158&#xFDCF;	DECODED
159&#xFDD0;	NOT DECODED
160&#xFDEF;	NOT DECODED
161&#xFDF0;	DECODED
162&#x2FFFE;	NOT DECODED
163&#x2FFFF;	NOT DECODED
164
165*** XML 1.0  ***
166&#0;	NOT DECODED
167&#1;	NOT DECODED
168&#x09;	DECODED
169&#x0A;	DECODED
170&#x0B;	NOT DECODED
171&#x0C;	NOT DECODED
172&#x0D;	DECODED
173&#x0E;	NOT DECODED
174&#x1F;	NOT DECODED
175&#x20;	DECODED
176&#x7F;	DECODED
177&#x80;	DECODED
178&#x9F;	DECODED
179&#xA0;	DECODED
180&#xD7FF;	DECODED
181&#xD800;	NOT DECODED
182&#xDFFF;	NOT DECODED
183&#xE000;	DECODED
184&#xFFFE;	NOT DECODED
185&#xFFFF;	NOT DECODED
186&#xFDCF;	DECODED
187&#xFDD0;	DECODED
188&#xFDEF;	DECODED
189&#xFDF0;	DECODED
190&#x2FFFE;	DECODED
191&#x2FFFF;	DECODED
192
193Done.
194