htmlentities22.phpt 11 KB

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