2004-11-06 02:51:43 +00:00
|
|
|
<?php
|
2010-08-15 07:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* Tests for UtfNormal::cleanUp() function.
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2004 Brion Vibber <brion@pobox.com>
|
2014-03-20 15:45:01 +00:00
|
|
|
* https://www.mediawiki.org/
|
2010-08-15 07:47:23 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2004-11-15 00:59:40 +00:00
|
|
|
|
2005-01-27 19:51:47 +00:00
|
|
|
/**
|
2007-04-24 06:53:31 +00:00
|
|
|
* Additional tests for UtfNormal::cleanUp() function, inclusion
|
|
|
|
|
* regression checks for known problems.
|
|
|
|
|
* Requires PHPUnit.
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup UtfNormal
|
2013-03-14 04:05:24 +00:00
|
|
|
* @group Large
|
2013-03-26 11:54:03 +00:00
|
|
|
*
|
2013-10-24 19:35:04 +00:00
|
|
|
* @todo covers tags, will be UtfNormal::cleanUp once the below is resolved
|
|
|
|
|
* @todo split me into test methods and providers per the below comment
|
|
|
|
|
*
|
2013-03-26 11:54:03 +00:00
|
|
|
* We ignore code coverage for this test suite until they are rewritten
|
|
|
|
|
* to use data providers (bug 46561).
|
|
|
|
|
* @codeCoverageIgnore
|
2005-01-27 19:51:47 +00:00
|
|
|
*/
|
2011-05-04 23:09:18 +00:00
|
|
|
class CleanUpTest extends MediaWikiTestCase {
|
2005-01-27 19:51:47 +00:00
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testAscii() {
|
2004-11-06 02:51:43 +00:00
|
|
|
$text = 'This is plain ASCII text.';
|
|
|
|
|
$this->assertEquals( $text, UtfNormal::cleanUp( $text ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testNull() {
|
2004-11-06 02:51:43 +00:00
|
|
|
$text = "a \x00 null";
|
|
|
|
|
$expect = "a \xef\xbf\xbd null";
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testLatin() {
|
2004-11-06 02:51:43 +00:00
|
|
|
$text = "L'\xc3\xa9cole";
|
|
|
|
|
$this->assertEquals( $text, UtfNormal::cleanUp( $text ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testLatinNormal() {
|
2004-11-06 02:51:43 +00:00
|
|
|
$text = "L'e\xcc\x81cole";
|
|
|
|
|
$expect = "L'\xc3\xa9cole";
|
|
|
|
|
$this->assertEquals( $expect, UtfNormal::cleanUp( $text ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This test is *very* expensive!
|
|
|
|
|
* @todo document
|
|
|
|
|
*/
|
2004-11-06 02:51:43 +00:00
|
|
|
function XtestAllChars() {
|
|
|
|
|
$rep = UTF8_REPLACEMENT;
|
2013-02-15 10:24:31 +00:00
|
|
|
for ( $i = 0x0; $i < UNICODE_MAX; $i++ ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$char = codepointToUtf8( $i );
|
|
|
|
|
$clean = UtfNormal::cleanUp( $char );
|
|
|
|
|
$x = sprintf( "%04X", $i );
|
2013-02-15 10:24:31 +00:00
|
|
|
|
|
|
|
|
if ( $i % 0x1000 == 0 ) {
|
|
|
|
|
echo "U+$x\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $i == 0x0009 ||
|
|
|
|
|
$i == 0x000a ||
|
|
|
|
|
$i == 0x000d ||
|
|
|
|
|
( $i > 0x001f && $i < UNICODE_SURROGATE_FIRST ) ||
|
|
|
|
|
( $i > UNICODE_SURROGATE_LAST && $i < 0xfffe ) ||
|
|
|
|
|
( $i > 0xffff && $i <= UNICODE_MAX )
|
|
|
|
|
) {
|
2014-04-24 17:52:09 +00:00
|
|
|
if ( isset( UtfNormal::$utfCanonicalComp[$char] )
|
|
|
|
|
|| isset( UtfNormal::$utfCanonicalDecomp[$char] )
|
|
|
|
|
) {
|
2013-02-15 10:24:31 +00:00
|
|
|
$comp = UtfNormal::NFC( $char );
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $comp ),
|
|
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"U+$x should be decomposed" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals(
|
2006-01-07 13:09:30 +00:00
|
|
|
bin2hex( $char ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"U+$x should be intact" );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals( bin2hex( $rep ), bin2hex( $clean ), $x );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/** @todo document */
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideAllBytes() {
|
2014-07-07 23:22:00 +00:00
|
|
|
return array(
|
|
|
|
|
array( '', '' ),
|
|
|
|
|
array( 'x', '' ),
|
|
|
|
|
array( '', 'x' ),
|
|
|
|
|
array( 'x', 'x' ),
|
|
|
|
|
);
|
2004-11-06 02:51:43 +00:00
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
2014-07-07 23:22:00 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideAllBytes
|
|
|
|
|
* @todo document
|
|
|
|
|
*/
|
|
|
|
|
function testBytes( $head, $tail ) {
|
2013-02-15 10:24:31 +00:00
|
|
|
for ( $i = 0x0; $i < 256; $i++ ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$char = $head . chr( $i ) . $tail;
|
|
|
|
|
$clean = UtfNormal::cleanUp( $char );
|
|
|
|
|
$x = sprintf( "%02X", $i );
|
2013-02-15 10:24:31 +00:00
|
|
|
|
|
|
|
|
if ( $i == 0x0009 ||
|
|
|
|
|
$i == 0x000a ||
|
|
|
|
|
$i == 0x000d ||
|
|
|
|
|
( $i > 0x001f && $i < 0x80 )
|
|
|
|
|
) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2006-01-07 13:09:30 +00:00
|
|
|
bin2hex( $char ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"ASCII byte $x should be intact" );
|
2013-02-15 10:24:31 +00:00
|
|
|
if ( $char != $clean ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-11-06 02:51:43 +00:00
|
|
|
} else {
|
2004-11-07 11:28:00 +00:00
|
|
|
$norm = $head . UTF8_REPLACEMENT . $tail;
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2004-11-07 11:28:00 +00:00
|
|
|
bin2hex( $norm ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Forbidden byte $x should be rejected" );
|
2013-02-15 10:24:31 +00:00
|
|
|
if ( $norm != $clean ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-11-06 02:51:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-07-07 23:22:00 +00:00
|
|
|
* @dataProvider provideAllBytes
|
2005-01-27 19:51:47 +00:00
|
|
|
* @todo document
|
|
|
|
|
*/
|
2014-07-07 23:22:00 +00:00
|
|
|
function testDoubleBytes( $head, $tail ) {
|
2013-02-15 10:24:31 +00:00
|
|
|
for ( $first = 0xc0; $first < 0x100; $first += 2 ) {
|
|
|
|
|
for ( $second = 0x80; $second < 0x100; $second += 2 ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$char = $head . chr( $first ) . chr( $second ) . $tail;
|
|
|
|
|
$clean = UtfNormal::cleanUp( $char );
|
|
|
|
|
$x = sprintf( "%02X,%02X", $first, $second );
|
2013-02-15 10:24:31 +00:00
|
|
|
if ( $first > 0xc1 &&
|
|
|
|
|
$first < 0xe0 &&
|
|
|
|
|
$second < 0xc0
|
|
|
|
|
) {
|
|
|
|
|
$norm = UtfNormal::NFC( $char );
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2006-01-07 13:09:30 +00:00
|
|
|
bin2hex( $norm ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Pair $x should be intact" );
|
2013-02-15 10:24:31 +00:00
|
|
|
if ( $norm != $clean ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $first > 0xfd || $second > 0xbf ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
# fe and ff are not legal head bytes -- expect two replacement chars
|
2004-11-07 11:28:00 +00:00
|
|
|
$norm = $head . UTF8_REPLACEMENT . UTF8_REPLACEMENT . $tail;
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2004-11-07 11:28:00 +00:00
|
|
|
bin2hex( $norm ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Forbidden pair $x should be rejected" );
|
2013-02-15 10:24:31 +00:00
|
|
|
if ( $norm != $clean ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-11-06 02:51:43 +00:00
|
|
|
} else {
|
2004-11-07 11:28:00 +00:00
|
|
|
$norm = $head . UTF8_REPLACEMENT . $tail;
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2004-11-07 11:28:00 +00:00
|
|
|
bin2hex( $norm ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Forbidden pair $x should be rejected" );
|
2013-02-15 10:24:31 +00:00
|
|
|
if ( $norm != $clean ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-11-06 02:51:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 23:22:00 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideAllBytes
|
|
|
|
|
* @todo document
|
|
|
|
|
*/
|
|
|
|
|
function testTripleBytes( $head, $tail ) {
|
2013-02-15 10:24:31 +00:00
|
|
|
for ( $first = 0xc0; $first < 0x100; $first += 2 ) {
|
|
|
|
|
for ( $second = 0x80; $second < 0x100; $second += 2 ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
#for( $third = 0x80; $third < 0x100; $third++ ) {
|
2013-02-15 10:24:31 +00:00
|
|
|
for ( $third = 0x80; $third < 0x81; $third++ ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$char = $head . chr( $first ) . chr( $second ) . chr( $third ) . $tail;
|
|
|
|
|
$clean = UtfNormal::cleanUp( $char );
|
|
|
|
|
$x = sprintf( "%02X,%02X,%02X", $first, $second, $third );
|
2013-02-15 10:24:31 +00:00
|
|
|
|
|
|
|
|
if ( $first >= 0xe0 &&
|
2004-11-06 02:51:43 +00:00
|
|
|
$first < 0xf0 &&
|
|
|
|
|
$second < 0xc0 &&
|
2013-02-15 10:24:31 +00:00
|
|
|
$third < 0xc0
|
|
|
|
|
) {
|
|
|
|
|
if ( $first == 0xe0 && $second < 0xa0 ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2006-01-07 13:09:30 +00:00
|
|
|
bin2hex( $head . UTF8_REPLACEMENT . $tail ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Overlong triplet $x should be rejected" );
|
2013-02-15 10:24:31 +00:00
|
|
|
} elseif ( $first == 0xed &&
|
|
|
|
|
( chr( $first ) . chr( $second ) . chr( $third ) ) >= UTF8_SURROGATE_FIRST
|
|
|
|
|
) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2006-01-07 13:09:30 +00:00
|
|
|
bin2hex( $head . UTF8_REPLACEMENT . $tail ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Surrogate triplet $x should be rejected" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals(
|
2011-03-27 12:21:45 +00:00
|
|
|
bin2hex( UtfNormal::NFC( $char ) ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Triplet $x should be intact" );
|
|
|
|
|
}
|
2013-02-15 10:24:31 +00:00
|
|
|
} elseif ( $first > 0xc1 && $first < 0xe0 && $second < 0xc0 ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2014-04-24 17:52:09 +00:00
|
|
|
bin2hex( UtfNormal::NFC( $head . chr( $first ) .
|
|
|
|
|
chr( $second ) ) . UTF8_REPLACEMENT . $tail ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Valid 2-byte $x + broken tail" );
|
2013-02-15 10:24:31 +00:00
|
|
|
} elseif ( $second > 0xc1 && $second < 0xe0 && $third < 0xc0 ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
2014-04-24 17:52:09 +00:00
|
|
|
bin2hex( $head . UTF8_REPLACEMENT .
|
|
|
|
|
UtfNormal::NFC( chr( $second ) . chr( $third ) . $tail ) ),
|
2004-11-06 02:51:43 +00:00
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Broken head + valid 2-byte $x" );
|
2013-02-15 10:24:31 +00:00
|
|
|
} elseif ( ( $first > 0xfd || $second > 0xfd ) &&
|
|
|
|
|
( ( $second > 0xbf && $third > 0xbf ) ||
|
|
|
|
|
( $second < 0xc0 && $third < 0xc0 ) ||
|
|
|
|
|
( $second > 0xfd ) ||
|
|
|
|
|
( $third > 0xfd ) )
|
|
|
|
|
) {
|
2004-11-06 02:51:43 +00:00
|
|
|
# fe and ff are not legal head bytes -- expect three replacement chars
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $head . UTF8_REPLACEMENT . UTF8_REPLACEMENT . UTF8_REPLACEMENT . $tail ),
|
|
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Forbidden triplet $x should be rejected" );
|
2013-02-15 10:24:31 +00:00
|
|
|
} elseif ( $first > 0xc2 && $second < 0xc0 && $third < 0xc0 ) {
|
2004-11-06 02:51:43 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $head . UTF8_REPLACEMENT . $tail ),
|
|
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Forbidden triplet $x should be rejected" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $head . UTF8_REPLACEMENT . UTF8_REPLACEMENT . $tail ),
|
|
|
|
|
bin2hex( $clean ),
|
|
|
|
|
"Forbidden triplet $x should be rejected" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
2006-01-07 13:31:29 +00:00
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testChunkRegression() {
|
2004-11-14 02:24:44 +00:00
|
|
|
# Check for regression against a chunking bug
|
2013-02-15 10:24:31 +00:00
|
|
|
$text = "\x46\x55\xb8" .
|
|
|
|
|
"\xdc\x96" .
|
|
|
|
|
"\xee" .
|
|
|
|
|
"\xe7" .
|
|
|
|
|
"\x44" .
|
|
|
|
|
"\xaa" .
|
|
|
|
|
"\x2f\x25";
|
2004-11-14 02:24:44 +00:00
|
|
|
$expect = "\x46\x55\xef\xbf\xbd" .
|
2013-02-15 10:24:31 +00:00
|
|
|
"\xdc\x96" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x44" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x2f\x25";
|
2004-11-14 02:24:44 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2004-11-06 02:51:43 +00:00
|
|
|
|
2005-01-27 19:51:47 +00:00
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testInterposeRegression() {
|
2013-02-15 10:24:31 +00:00
|
|
|
$text = "\x4e\x30" .
|
|
|
|
|
"\xb1" . # bad tail
|
|
|
|
|
"\x3a" .
|
|
|
|
|
"\x92" . # bad tail
|
|
|
|
|
"\x62\x3a" .
|
|
|
|
|
"\x84" . # bad tail
|
|
|
|
|
"\x43" .
|
|
|
|
|
"\xc6" . # bad head
|
|
|
|
|
"\x3f" .
|
|
|
|
|
"\x92" . # bad tail
|
|
|
|
|
"\xad" . # bad tail
|
|
|
|
|
"\x7d" .
|
|
|
|
|
"\xd9\x95";
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-11-14 03:48:49 +00:00
|
|
|
$expect = "\x4e\x30" .
|
2013-02-15 10:24:31 +00:00
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x3a" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x62\x3a" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x43" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x3f" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x7d" .
|
|
|
|
|
"\xd9\x95";
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-11-14 03:48:49 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
2006-01-07 13:31:29 +00:00
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testOverlongRegression() {
|
2013-02-15 10:24:31 +00:00
|
|
|
$text = "\x67" .
|
|
|
|
|
"\x1a" . # forbidden ascii
|
|
|
|
|
"\xea" . # bad head
|
|
|
|
|
"\xc1\xa6" . # overlong sequence
|
|
|
|
|
"\xad" . # bad tail
|
|
|
|
|
"\x1c" . # forbidden ascii
|
|
|
|
|
"\xb0" . # bad tail
|
|
|
|
|
"\x3c" .
|
|
|
|
|
"\x9e"; # bad tail
|
2004-11-14 04:07:28 +00:00
|
|
|
$expect = "\x67" .
|
2013-02-15 10:24:31 +00:00
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x3c" .
|
|
|
|
|
"\xef\xbf\xbd";
|
2004-11-14 04:07:28 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
2006-01-07 13:31:29 +00:00
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testSurrogateRegression() {
|
2013-02-15 10:24:31 +00:00
|
|
|
$text = "\xed\xb4\x96" . # surrogate 0xDD16
|
|
|
|
|
"\x83" . # bad tail
|
|
|
|
|
"\xb4" . # bad tail
|
|
|
|
|
"\xac"; # bad head
|
2004-11-14 04:27:03 +00:00
|
|
|
$expect = "\xef\xbf\xbd" .
|
2013-02-15 10:24:31 +00:00
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd";
|
2004-11-14 04:27:03 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testBomRegression() {
|
2013-02-15 10:24:31 +00:00
|
|
|
$text = "\xef\xbf\xbe" . # U+FFFE, illegal char
|
|
|
|
|
"\xb2" . # bad tail
|
|
|
|
|
"\xef" . # bad head
|
|
|
|
|
"\x59";
|
2004-11-14 05:17:29 +00:00
|
|
|
$expect = "\xef\xbf\xbd" .
|
2013-02-15 10:24:31 +00:00
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\xef\xbf\xbd" .
|
|
|
|
|
"\x59";
|
2004-11-14 05:17:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2004-11-14 21:36:43 +00:00
|
|
|
|
2005-01-27 19:51:47 +00:00
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testForbiddenRegression() {
|
2013-02-15 10:24:31 +00:00
|
|
|
$text = "\xef\xbf\xbf"; # U+FFFF, illegal char
|
2004-11-14 21:36:43 +00:00
|
|
|
$expect = "\xef\xbf\xbd";
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
|
|
|
|
/** @todo document */
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testHangulRegression() {
|
2004-11-15 00:59:40 +00:00
|
|
|
$text = "\xed\x9c\xaf" . # Hangul char
|
2013-02-15 10:24:31 +00:00
|
|
|
"\xe1\x87\x81"; # followed by another final jamo
|
|
|
|
|
$expect = $text; # Should *not* change.
|
2004-11-15 00:59:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
bin2hex( $expect ),
|
|
|
|
|
bin2hex( UtfNormal::cleanUp( $text ) ) );
|
|
|
|
|
}
|
2004-11-06 02:51:43 +00:00
|
|
|
}
|