框架升级及修复升级后的bug
This commit is contained in:
+26
-22
@@ -41,29 +41,33 @@ class Normalizer
|
||||
private static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4];
|
||||
private static $ASCII = "\x20\x65\x69\x61\x73\x6E\x74\x72\x6F\x6C\x75\x64\x5D\x5B\x63\x6D\x70\x27\x0A\x67\x7C\x68\x76\x2E\x66\x62\x2C\x3A\x3D\x2D\x71\x31\x30\x43\x32\x2A\x79\x78\x29\x28\x4C\x39\x41\x53\x2F\x50\x22\x45\x6A\x4D\x49\x6B\x33\x3E\x35\x54\x3C\x44\x34\x7D\x42\x7B\x38\x46\x77\x52\x36\x37\x55\x47\x4E\x3B\x4A\x7A\x56\x23\x48\x4F\x57\x5F\x26\x21\x4B\x3F\x58\x51\x25\x59\x5C\x09\x5A\x2B\x7E\x5E\x24\x40\x60\x7F\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
|
||||
|
||||
public static function isNormalized(string $s, int $form = self::FORM_C)
|
||||
public static function isNormalized(string $string, int $form = self::FORM_C)
|
||||
{
|
||||
if (!\in_array($form, [self::NFD, self::NFKD, self::NFC, self::NFKC])) {
|
||||
return false;
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \ValueError('normalizer_is_normalized(): Argument #2 ($form) must be a '.(80600 > \PHP_VERSION_ID ? 'a ' : '').'valid normalization form');
|
||||
}
|
||||
if (!isset($s[strspn($s, self::$ASCII)])) {
|
||||
if (!isset($string[strspn($string, self::$ASCII)])) {
|
||||
return true;
|
||||
}
|
||||
if (self::NFC == $form && preg_match('//u', $s) && !preg_match('/[^\x00-\x{2FF}]/u', $s)) {
|
||||
if (self::NFC == $form && preg_match('//u', $string) && !preg_match('/[^\x00-\x{2FF}]/u', $string)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return self::normalize($s, $form) === $s;
|
||||
return self::normalize($string, $form) === $string;
|
||||
}
|
||||
|
||||
public static function getRawDecomposition(string $s, int $form = self::FORM_C)
|
||||
public static function getRawDecomposition(string $string, int $form = self::FORM_C)
|
||||
{
|
||||
if ('' === $s || !preg_match('//u', $s)) {
|
||||
if ('' === $string || !preg_match('//u', $string)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ulen = $s[0] < "\x80" ? 1 : (self::$ulenMask[$s[0] & "\xF0"] ?? 0);
|
||||
if (!$ulen || \strlen($s) !== $ulen) {
|
||||
$ulen = $string[0] < "\x80" ? 1 : (self::$ulenMask[$string[0] & "\xF0"] ?? 0);
|
||||
if (!$ulen || \strlen($string) !== $ulen) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -71,8 +75,8 @@ class Normalizer
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($s >= "\xEA\xB0\x80" && $s <= "\xED\x9E\xA3") {
|
||||
$u = unpack('C*', $s);
|
||||
if ($string >= "\xEA\xB0\x80" && $string <= "\xED\x9E\xA3") {
|
||||
$u = unpack('C*', $string);
|
||||
$j = (($u[1] - 224) << 12) + (($u[2] - 128) << 6) + $u[3] - 0xAC80;
|
||||
|
||||
if ($t = $j % 28) {
|
||||
@@ -94,8 +98,8 @@ class Normalizer
|
||||
self::$rawD = self::getData('rawCanonicalDecomposition');
|
||||
}
|
||||
|
||||
if (isset(self::$rawD[$s])) {
|
||||
return self::$rawD[$s];
|
||||
if (isset(self::$rawD[$string])) {
|
||||
return self::$rawD[$string];
|
||||
}
|
||||
|
||||
if (self::NFKC === $form || self::NFKD === $form) {
|
||||
@@ -103,18 +107,14 @@ class Normalizer
|
||||
self::$rawKD = self::getData('rawCompatibilityDecomposition');
|
||||
}
|
||||
|
||||
return self::$rawKD[$s] ?? null;
|
||||
return self::$rawKD[$string] ?? null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function normalize(string $s, int $form = self::FORM_C)
|
||||
public static function normalize(string $string, int $form = self::FORM_C)
|
||||
{
|
||||
if (!preg_match('//u', $s)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($form) {
|
||||
case self::NFC: $C = true; $K = false; break;
|
||||
case self::NFD: $C = false; $K = false; break;
|
||||
@@ -122,7 +122,7 @@ class Normalizer
|
||||
case self::NFKD: $C = false; $K = true; break;
|
||||
default:
|
||||
if (\defined('Normalizer::NONE') && \Normalizer::NONE == $form) {
|
||||
return $s;
|
||||
return preg_match('//u', $string) ? $string : false;
|
||||
}
|
||||
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
@@ -133,7 +133,11 @@ class Normalizer
|
||||
throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a '.(80600 > \PHP_VERSION_ID ? 'a ' : '').'valid normalization form');
|
||||
}
|
||||
|
||||
if ('' === $s) {
|
||||
if (!preg_match('//u', $string)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ('' === $string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -150,7 +154,7 @@ class Normalizer
|
||||
mb_internal_encoding('8bit');
|
||||
}
|
||||
|
||||
$r = self::decompose($s, $K);
|
||||
$r = self::decompose($string, $K);
|
||||
|
||||
if ($C) {
|
||||
if (null === self::$C) {
|
||||
|
||||
Reference in New Issue
Block a user