Skip to content

Commit fd51778

Browse files
committed
bugfix issue #230
1 parent a59ca54 commit fd51778

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ All Notable changes to `PHP Domain Parser` **5.x** series will be documented in
1919
### Fixed
2020

2121
- `Pdp\IDNAConverterTrait::setLabels` improve IDN domain handling
22+
- `Pdp\IDNAConverterTrait` throws a `UnexpectedValueException` if the Intl extension is misconfigured see [#230](https://github.com/jeremykendall/php-domain-parser/issues/230)
2223

2324
### Deprecated
2425

src/IDNAConverterTrait.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use Pdp\Exception\InvalidDomain;
1919
use TypeError;
20+
use UnexpectedValueException;
2021
use function array_reverse;
2122
use function explode;
2223
use function gettype;
@@ -119,6 +120,12 @@ private function idnToAscii(string $domain): string
119120
throw new InvalidDomain(sprintf('The host `%s` is invalid : %s', $domain, self::getIdnErrors($arr['errors'])));
120121
}
121122

123+
// @codeCoverageIgnoreStart
124+
if (false === $output) {
125+
throw new UnexpectedValueException(sprintf('The Intl extension is misconfigured for %s, please correct this issue before proceeding.', PHP_OS));
126+
}
127+
// @codeCoverageIgnoreEnd
128+
122129
if (false === strpos($output, '%')) {
123130
return $output;
124131
}
@@ -140,11 +147,17 @@ private function idnToAscii(string $domain): string
140147
private function idnToUnicode(string $domain): string
141148
{
142149
$output = idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46, $arr);
143-
if (0 === $arr['errors']) {
144-
return $output;
150+
if (0 !== $arr['errors']) {
151+
throw new InvalidDomain(sprintf('The host `%s` is invalid : %s', $domain, self::getIdnErrors($arr['errors'])));
152+
}
153+
154+
// @codeCoverageIgnoreStart
155+
if (false === $output) {
156+
throw new UnexpectedValueException(sprintf('The Intl extension is misconfigured for %s, please correct this issue before proceeding.', PHP_OS));
145157
}
158+
// @codeCoverageIgnoreEnd
146159

147-
throw new InvalidDomain(sprintf('The host `%s` is invalid : %s', $domain, self::getIdnErrors($arr['errors'])));
160+
return $output;
148161
}
149162

150163
/**

0 commit comments

Comments
 (0)