diff --git a/CHANGELOG.md b/CHANGELOG.md index 2650fc1..3a780ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All Notable changes to `league-uri-parser` will be documented in this file +## 1.0.3 - 2017-02-06 + +### Added + +- None + +### Fixed + +- idn_to_ascii uses `INTL_IDNA_VARIANT_UTS46` as `INTL_IDNA_VARIANT_2003` will be deprecated + +### Deprecated + +- None + +### Removed + +- None + ## 1.0.2 - 2017-01-19 ### Added diff --git a/composer.json b/composer.json index deafade..3315b4a 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^1.9", - "phpunit/phpunit" : "^5.0", + "phpunit/phpunit" : "^6.0", "phpbench/phpbench": "^0.12.2" }, "autoload": { diff --git a/src/Parser.php b/src/Parser.php index 1659a19..c451ca5 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -333,11 +333,29 @@ protected function isRegisteredName(string $host): bool $host = substr($host, 0, -1); } - $labels = array_map('idn_to_ascii', explode('.', $host)); + $labels = array_map([$this, 'toAscii'], explode('.', $host)); return 127 > count($labels) && $labels === array_filter($labels, [$this, 'isHostLabel']); } + /** + * Convert domain name to IDNA ASCII form. + * + * @param string $label + * + * @return string + */ + protected function toAscii(string $label) + { + $res = idn_to_ascii($label, 0, INTL_IDNA_VARIANT_UTS46); + if (false !== $res) { + return $res; + } + + return ''; + } + + /** * Returns whether the host label is valid * diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 6368d39..98ae6ba 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -12,26 +12,17 @@ class ParserTest extends TestCase { /** - * @var Parser - */ - protected $parser; - - protected function setUp() - { - $this->parser = new Parser(); - } - - /** - * @dataProvider testValidURI + * @dataProvider validUriProvider * @param $uri * @param $expected */ public function testParseSucced($uri, $expected) { - $this->assertSame($expected, $this->parser->__invoke($uri)); + $components = (new Parser())($uri); + $this->assertSame($expected, $components); } - public function testValidURI() + public function validUriProvider() { return [ 'complete URI' => [ @@ -86,7 +77,6 @@ public function testValidURI() 'fragment' => null, ], ], - 'URI without userinfo' => [ 'scheme://HoSt:81/path?query#fragment', [ @@ -637,16 +627,16 @@ public function testValidURI() } /** - * @dataProvider testInvalidURI + * @dataProvider invalidUriProvider * @param string $uri */ public function testParseFailed($uri) { - $this->setExpectedException(Exception::class); - $this->parser->__invoke($uri); + $this->expectException(Exception::class); + (new Parser())($uri); } - public function testInvalidURI() + public function invalidUriProvider() { return [ 'invalid scheme (1)' => ['0scheme://host/path?query#fragment'], @@ -670,14 +660,14 @@ public function testInvalidURI() } /** - * @dataProvider testValidHost + * @dataProvider validHostProvider */ public function testHost($host, $expected) { - $this->assertSame($expected, $this->parser->isHost($host)); + $this->assertSame($expected, (new Parser())->isHost($host)); } - public function testValidHost() + public function validHostProvider() { return [ 'RFC3986 registered name' => ['bebe.be', true],