Changeset View
Changeset View
Standalone View
Standalone View
src/utils/__tests__/PhutilUTF8TestCase.php
| Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | $map = array( | ||||
| // This is a 3-byte encoding of U+0020. | // This is a 3-byte encoding of U+0020. | ||||
| "\xE0\x80\xA0" => "{$bad}{$bad}{$bad}", | "\xE0\x80\xA0" => "{$bad}{$bad}{$bad}", | ||||
| "A \xE0\x83\x83" => "A {$bad}{$bad}{$bad}", | "A \xE0\x83\x83" => "A {$bad}{$bad}{$bad}", | ||||
| ); | ); | ||||
| foreach ($map as $input => $expect) { | foreach ($map as $input => $expect) { | ||||
| if ($input !== $expect) { | |||||
| $this->assertEqual( | |||||
| false, | |||||
| phutil_is_utf8_slowly($input), | |||||
| pht('Slowly reject overlong form of: %s', $input)); | |||||
| } | |||||
| $actual = phutil_utf8ize($input); | $actual = phutil_utf8ize($input); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $expect, | $expect, | ||||
| $actual, | $actual, | ||||
| pht('Overlong form canonicalization of: %s', $input)); | pht('Overlong form canonicalization of: %s', $input)); | ||||
| } | } | ||||
| } | } | ||||
| public function testSurrogateFiltering() { | public function testSurrogateFiltering() { | ||||
| $bad = "\xEF\xBF\xBD"; | $bad = "\xEF\xBF\xBD"; | ||||
| $map = array( | $map = array( | ||||
| "A \xED\xA9\x98" => "A {$bad}{$bad}{$bad}", | "A \xED\xA9\x98" => "A {$bad}{$bad}{$bad}", | ||||
| ); | ); | ||||
| foreach ($map as $input => $expect) { | foreach ($map as $input => $expect) { | ||||
| if ($input !== $expect) { | |||||
| $this->assertEqual( | |||||
| false, | |||||
| phutil_is_utf8_slowly($input), | |||||
| pht('Slowly reject surrogate: %s', $input)); | |||||
| } | |||||
| $actual = phutil_utf8ize($input); | $actual = phutil_utf8ize($input); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $expect, | $expect, | ||||
| $actual, | $actual, | ||||
| pht('Surrogate filtering: %s', $input)); | pht('Surrogate filtering: %s', $input)); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 726 Lines • Show Last 20 Lines | |||||