Skip to content

Commit 65eb0da

Browse files
committed
fix: wraps internal idn exceptions on PHP 8.4
1 parent 66afa1e commit 65eb0da

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Utils/Idn.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public static function toAscii(array|string $domain): string
2121
if (\is_array($domain)) {
2222
$domain = implode('.', $domain);
2323
}
24-
$idn = idn_to_ascii($domain, self::TO_ASCII_FLAGS, \INTL_IDNA_VARIANT_UTS46, $info);
24+
try {
25+
$idn = idn_to_ascii($domain, self::TO_ASCII_FLAGS, \INTL_IDNA_VARIANT_UTS46, $info);
26+
} catch (\ValueError $err) {
27+
throw new IdnException($err->getMessage(), $err->getCode(), $err);
28+
}
2529
if ($idn === false) {
2630
throw IdnException::toAscii($domain, $info);
2731
}
@@ -37,7 +41,11 @@ public static function toUnicode(array|string $domain): string
3741
if (\is_array($domain)) {
3842
$domain = implode('.', $domain);
3943
}
40-
$idn = idn_to_utf8($domain, self::TO_UTF8_FLAGS, \INTL_IDNA_VARIANT_UTS46, $info);
44+
try {
45+
$idn = idn_to_utf8($domain, self::TO_UTF8_FLAGS, \INTL_IDNA_VARIANT_UTS46, $info);
46+
} catch (\ValueError $err) {
47+
throw new IdnException($err->getMessage(), $err->getCode(), $err);
48+
}
4149
if ($idn === false) {
4250
throw IdnException::toUnicode($domain, $info);
4351
}

0 commit comments

Comments
 (0)