1--TEST-- 2htmlentities() / htmlspecialchars() ENT_DISALLOWED with entities and no double encode 3--FILE-- 4<?php 5$tests = array( 6 "�", //C0 7 "", 8 "	", 9 "
", 10 "", 11 "", 12 "
", //note that HTML5 is unique in that it forbids this entity, but allows a literal U+0D 13 "", 14 "", 15 " ", //allowed always 16 "", //DEL 17 "€", //C1 18 "Ÿ", 19 " ", //allowed always 20 "퟿", //surrogates 21 "�", 22 "�", 23 "", //allowed always 24 "", //nonchar 25 "", 26 "﷏", //allowed always 27 "", //nonchar 28 "", 29 "ﷰ", //allowed always 30 "", //nonchar 31 "", 32 "�", //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� NOT CHANGED 84 NOT CHANGED 85	 NOT CHANGED 86
 NOT CHANGED 87 NOT CHANGED 88 NOT CHANGED 89
 NOT CHANGED 90 NOT CHANGED 91 NOT CHANGED 92  NOT CHANGED 93 NOT CHANGED 94€ NOT CHANGED 95Ÿ NOT CHANGED 96  NOT CHANGED 97퟿ NOT CHANGED 98� NOT CHANGED 99� NOT CHANGED 100 NOT CHANGED 101 NOT CHANGED 102 NOT CHANGED 103﷏ NOT CHANGED 104 NOT CHANGED 105 NOT CHANGED 106ﷰ NOT CHANGED 107 NOT CHANGED 108 NOT CHANGED 109� CHANGED 110 111*** Testing XHTML 1.0 *** 112� CHANGED 113 CHANGED 114	 NOT CHANGED 115
 NOT CHANGED 116 CHANGED 117 CHANGED 118
 NOT CHANGED 119 CHANGED 120 CHANGED 121  NOT CHANGED 122 NOT CHANGED 123€ NOT CHANGED 124Ÿ NOT CHANGED 125  NOT CHANGED 126퟿ NOT CHANGED 127� CHANGED 128� CHANGED 129 NOT CHANGED 130 CHANGED 131 CHANGED 132﷏ NOT CHANGED 133 NOT CHANGED 134 NOT CHANGED 135ﷰ NOT CHANGED 136 NOT CHANGED 137 NOT CHANGED 138� CHANGED 139 140*** Testing HTML 5 *** 141� CHANGED (&#0;, &#0;) 142 CHANGED (&#1;, &#1;) 143	 NOT CHANGED 144
 NOT CHANGED 145 CHANGED (&#x0B;, &#x0B;) 146 NOT CHANGED 147
 CHANGED (&#x0D;, &#x0D;) 148 CHANGED (&#x0E;, &#x0E;) 149 CHANGED (&#x1F;, &#x1F;) 150  NOT CHANGED 151 CHANGED (&#x7F;, &#x7F;) 152€ CHANGED (&#x80;, &#x80;) 153Ÿ CHANGED (&#x9F;, &#x9F;) 154  NOT CHANGED 155퟿ NOT CHANGED 156� NOT CHANGED 157� NOT CHANGED 158 NOT CHANGED 159 CHANGED (&#xFFFE;, &#xFFFE;) 160 CHANGED (&#xFFFF;, &#xFFFF;) 161﷏ NOT CHANGED 162 CHANGED (&#xFDD0;, &#xFDD0;) 163 CHANGED (&#xFDEF;, &#xFDEF;) 164ﷰ NOT CHANGED 165 CHANGED (&#x2FFFE;, &#x2FFFE;) 166 CHANGED (&#x2FFFF;, &#x2FFFF;) 167� CHANGED (&#x110000;, &#x110000;) 168 169*** Testing XML 1.0 *** 170� CHANGED 171 CHANGED 172	 NOT CHANGED 173
 NOT CHANGED 174 CHANGED 175 CHANGED 176
 NOT CHANGED 177 CHANGED 178 CHANGED 179  NOT CHANGED 180 NOT CHANGED 181€ NOT CHANGED 182Ÿ NOT CHANGED 183  NOT CHANGED 184퟿ NOT CHANGED 185� CHANGED 186� CHANGED 187 NOT CHANGED 188 CHANGED 189 CHANGED 190﷏ NOT CHANGED 191 NOT CHANGED 192 NOT CHANGED 193ﷰ NOT CHANGED 194 NOT CHANGED 195 NOT CHANGED 196� CHANGED 197 198*** Testing 5 without the flag *** 199� NOT CHANGED 200 NOT CHANGED 201	 NOT CHANGED 202
 NOT CHANGED 203 NOT CHANGED 204 NOT CHANGED 205
 NOT CHANGED 206 NOT CHANGED 207 NOT CHANGED 208  NOT CHANGED 209 NOT CHANGED 210€ NOT CHANGED 211Ÿ NOT CHANGED 212  NOT CHANGED 213퟿ NOT CHANGED 214� NOT CHANGED 215� NOT CHANGED 216 NOT CHANGED 217 NOT CHANGED 218 NOT CHANGED 219﷏ NOT CHANGED 220 NOT CHANGED 221 NOT CHANGED 222ﷰ NOT CHANGED 223 NOT CHANGED 224 NOT CHANGED 225� CHANGED (&#x110000;, &#x110000;) 226 227*** Testing HTML 5 with another single-byte encoding *** 228� CHANGED (&#0;, &#0;) 229 CHANGED (&#1;, &#1;) 230	 NOT CHANGED 231
 NOT CHANGED 232 CHANGED (&#x0B;, &#x0B;) 233 NOT CHANGED 234
 CHANGED (&#x0D;, &#x0D;) 235 CHANGED (&#x0E;, &#x0E;) 236 CHANGED (&#x1F;, &#x1F;) 237  NOT CHANGED 238 CHANGED (&#x7F;, &#x7F;) 239€ CHANGED (&#x80;, &#x80;) 240Ÿ CHANGED (&#x9F;, &#x9F;) 241  NOT CHANGED 242퟿ NOT CHANGED 243� NOT CHANGED 244� NOT CHANGED 245 NOT CHANGED 246 CHANGED (&#xFFFE;, &#xFFFE;) 247 CHANGED (&#xFFFF;, &#xFFFF;) 248﷏ NOT CHANGED 249 CHANGED (&#xFDD0;, &#xFDD0;) 250 CHANGED (&#xFDEF;, &#xFDEF;) 251ﷰ NOT CHANGED 252 CHANGED (&#x2FFFE;, &#x2FFFE;) 253 CHANGED (&#x2FFFF;, &#x2FFFF;) 254� CHANGED (&#x110000;, &#x110000;) 255 256*** Testing HTML 5 with another multibyte-byte encoding *** 257� CHANGED 258 CHANGED 259	 NOT CHANGED 260
 NOT CHANGED 261 CHANGED 262 NOT CHANGED 263
 CHANGED 264 CHANGED 265 CHANGED 266  NOT CHANGED 267 CHANGED 268€ CHANGED 269Ÿ CHANGED 270  NOT CHANGED 271퟿ NOT CHANGED 272� NOT CHANGED 273� NOT CHANGED 274 NOT CHANGED 275 CHANGED 276 CHANGED 277﷏ NOT CHANGED 278 CHANGED 279 CHANGED 280ﷰ NOT CHANGED 281 CHANGED 282 CHANGED 283� CHANGED 284