Skip to content

Commit

Permalink
IDN functions in PHP are limited to 61 characters (#80)
Browse files Browse the repository at this point in the history
* IDNA functions in PHP are limited to 61 characters, skip the IDNA encoding if the provided URL is longer than that

* cleanup
  • Loading branch information
mattiasgeniar authored and freekmurze committed Dec 3, 2018
1 parent 60d5620 commit ac3d42b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(string $url)
$url = "https://{$url}";
}

if (function_exists('idn_to_ascii')) {
if (strlen($url) < 61 && function_exists('idn_to_ascii')) {
$url = idn_to_ascii($url, false, INTL_IDNA_VARIANT_UTS46);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ public function it_can_retrieve_the_custom_port_when_defined()

$this->assertSame(12345, $url->getPort());
}

/** @test */
public function it_can_parse_really_long_paths()
{
$url = new Url('https://random.host/this-is-a-very/and-i-mean-very/long-path/to-work/with/and-somehow/the-idna-functions-in-php/are-limited-to/61-chars/yes?really=true&ohmy');

$this->assertSame('random.host', $url->getHostName());
}
}

0 comments on commit ac3d42b

Please sign in to comment.