Skip to content

Commit f6a54a9

Browse files
authored
Merge pull request #256 from jeremykendall/bugfix/idn_functions_usage
bugfix idn functions usage
2 parents b234707 + a091910 commit f6a54a9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

data/pdp-PSL_FULL_5a3cc7f81795bb2e48e848af42d287b4.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/IDNAConverterTrait.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ private function transformToAscii(string $domain, int $option): array
138138
}
139139

140140
$output = idn_to_ascii($domain, $option, INTL_IDNA_VARIANT_UTS46, $infos);
141+
if ([] === $infos) {
142+
throw new InvalidDomain(sprintf('The host `%s` is invalid', $domain));
143+
}
144+
141145
if (0 !== $infos['errors']) {
142146
throw new InvalidDomain(sprintf('The host `%s` is invalid : %s', $domain, self::getIdnErrors($infos['errors'])));
143147
}
@@ -170,9 +174,13 @@ private function transformToAscii(string $domain, int $option): array
170174
*/
171175
private function idnToUnicode(string $domain, int $option = IDNA_DEFAULT): string
172176
{
173-
$output = idn_to_utf8($domain, $option, INTL_IDNA_VARIANT_UTS46, $arr);
174-
if (0 !== $arr['errors']) {
175-
throw new InvalidDomain(sprintf('The host `%s` is invalid : %s', $domain, self::getIdnErrors($arr['errors'])));
177+
$output = idn_to_utf8($domain, $option, INTL_IDNA_VARIANT_UTS46, $info);
178+
if ([] === $info) {
179+
throw new InvalidDomain(sprintf('The host `%s` is invalid', $domain));
180+
}
181+
182+
if (0 !== $info['errors']) {
183+
throw new InvalidDomain(sprintf('The host `%s` is invalid : %s', $domain, self::getIdnErrors($info['errors'])));
176184
}
177185

178186
// @codeCoverageIgnoreStart

0 commit comments

Comments
 (0)