44 $text =
'This is plain ASCII text.';
50 $text =
"a \x00 null";
51 $expect =
"a \xef\xbf\xbd null";
59 $text =
"L'\xc3\xa9cole";
65 $text =
"L'e\xcc\x81cole";
66 $expect =
"L'\xc3\xa9cole";
79 $x = sprintf(
"%04X", $i );
81 if ( $i % 0x1000 == 0 ) {
97 "U+$x should be decomposed" );
102 "U+$x should be intact" );
105 $this->assertEquals( bin2hex( $rep ), bin2hex( $clean ), $x );
120 for ( $i = 0x0; $i < 256; $i++ ) {
121 $char = $head . chr( $i ) . $tail;
123 $x = sprintf(
"%02X", $i );
128 ( $i > 0x001f && $i < 0x80 )
133 "ASCII byte $x should be intact" );
134 if ( $char != $clean ) {
142 "Forbidden byte $x should be rejected" );
143 if ( $norm != $clean ) {
162 for ( $first = 0xc0; $first < 0x100; $first += 2 ) {
163 for ( $second = 0x80; $second < 0x100; $second += 2 ) {
164 $char = $head . chr( $first ) . chr( $second ) . $tail;
166 $x = sprintf(
"%02X,%02X", $first, $second );
167 if ( $first > 0xc1 &&
175 "Pair $x should be intact" );
176 if ( $norm != $clean ) {
179 } elseif ( $first > 0xfd || $second > 0xbf ) {
180 # fe and ff are not legal head bytes -- expect two replacement chars
185 "Forbidden pair $x should be rejected" );
186 if ( $norm != $clean ) {
194 "Forbidden pair $x should be rejected" );
195 if ( $norm != $clean ) {
213 for ( $first = 0xc0; $first < 0x100; $first += 2 ) {
214 for ( $second = 0x80; $second < 0x100; $second += 2 ) {
215 #for( $third = 0x80; $third < 0x100; $third++ ) {
216 for ( $third = 0x80; $third < 0x81; $third++ ) {
217 $char = $head . chr( $first ) . chr( $second ) . chr( $third ) . $tail;
219 $x = sprintf(
"%02X,%02X,%02X", $first, $second, $third );
221 if ( $first >= 0xe0 &&
226 if ( $first == 0xe0 && $second < 0xa0 ) {
230 "Overlong triplet $x should be rejected" );
231 } elseif ( $first == 0xed &&
237 "Surrogate triplet $x should be rejected" );
242 "Triplet $x should be intact" );
244 } elseif ( $first > 0xc1 && $first < 0xe0 && $second < 0xc0 ) {
248 "Valid 2-byte $x + broken tail" );
249 } elseif ( $second > 0xc1 && $second < 0xe0 && $third < 0xc0 ) {
253 "Broken head + valid 2-byte $x" );
254 } elseif ( ( $first > 0xfd || $second > 0xfd ) &&
255 ( ( $second > 0xbf && $third > 0xbf ) ||
256 ( $second < 0xc0 && $third < 0xc0 ) ||
257 ( $second > 0xfd ) ||
260 # fe and ff are not legal head bytes -- expect three replacement chars
264 "Forbidden triplet $x should be rejected" );
265 } elseif ( $first > 0xc2 && $second < 0xc0 && $third < 0xc0 ) {
269 "Forbidden triplet $x should be rejected" );
274 "Forbidden triplet $x should be rejected" );
283 # Check for regression against a chunking bug
284 $text =
"\x46\x55\xb8" .
291 $expect =
"\x46\x55\xef\xbf\xbd" .
320 $expect =
"\x4e\x30" .
342 "\x1a" . # forbidden ascii
344 "\xc1\xa6" . # overlong sequence
346 "\x1c" . # forbidden ascii
366 $text =
"\xed\xb4\x96" . # surrogate 0xDD16
370 $expect =
"\xef\xbf\xbd" .
381 $text =
"\xef\xbf\xbe" . # U+FFFE, illegal
char
385 $expect =
"\xef\xbf\xbd" .
396 $text =
"\xef\xbf\xbf"; # U+FFFF, illegal
char
397 $expect =
"\xef\xbf\xbd";
405 $text =
"\xed\x9c\xaf" . # Hangul
char
406 "\xe1\x87\x81"; # followed by another
final jamo
407 $expect = $text; # Should *not*
change.