@@ -21,7 +21,11 @@ public static function toAscii(array|string $domain): string
21
21
if (\is_array ($ domain )) {
22
22
$ domain = implode ('. ' , $ domain );
23
23
}
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
+ }
25
29
if ($ idn === false ) {
26
30
throw IdnException::toAscii ($ domain , $ info );
27
31
}
@@ -37,7 +41,11 @@ public static function toUnicode(array|string $domain): string
37
41
if (\is_array ($ domain )) {
38
42
$ domain = implode ('. ' , $ domain );
39
43
}
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
+ }
41
49
if ($ idn === false ) {
42
50
throw IdnException::toUnicode ($ domain , $ info );
43
51
}
0 commit comments