fix: keystore

This commit is contained in:
hashbro
2026-09-20 06:15:26 +08:00
parent 2625707aed
commit 2a41a29310
29 changed files with 1972 additions and 66 deletions
+11 -4
View File
@@ -16,15 +16,22 @@ final class CfIpCountry
public static function normalize(?string $raw): ?string
{
$code = strtoupper(trim((string) $raw));
$trimmed = trim((string) $raw);
if ($trimmed === '') {
return null;
}
$code = strtoupper($trimmed);
if ($code === 'T1') {
return 'T1';
}
if (preg_match('/^[A-Z]{2}$/', $code) !== 1) {
return null;
if (preg_match('/^[A-Z]{2}$/', $code) === 1) {
return $code;
}
return $code;
// Allow Chinese country names (e.g. "中国" -> "CN") via reverse lookup.
$hit = array_search($trimmed, self::names(), true);
return $hit !== false ? (string) $hit : null;
}
public static function label(?string $code): string