Skip to content

Commit

Permalink
added support for IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
mildabre committed Dec 2, 2024
1 parent 9e4dc62 commit 4ce2a5b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
if ($this->type === self::Host) {
$host = $url->getHost();
$path = '//' . $host . $url->getPath();
$parts = ip2long($host)
? [$host]
: array_reverse(explode('.', $host));
$parts = filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
? [$host]
: array_reverse(explode('.', $host));
$re = strtr($re, [
'/%basePath%/' => preg_quote($url->getBasePath(), '#'),
'%tld%' => preg_quote($parts[0], '#'),
Expand Down Expand Up @@ -269,10 +269,10 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri

} else {
$host = $refUrl->getHost();
$parts = ip2long($host)
? [$host]
: array_reverse(explode('.', $host));
$port = $refUrl->getDefaultPort() === ($tmp = $refUrl->getPort()) ? '' : ':' . $tmp;
$parts = filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
? [$host]
: array_reverse(explode('.', $host));
$port = $refUrl->getDefaultPort() === ($tmp = $refUrl->getPort()) ? '' : ':' . $tmp;
$url = strtr($url, [
'/%basePath%/' => $refUrl->getBasePath(),
'%tld%' => $parts[0] . $port,
Expand Down

0 comments on commit 4ce2a5b

Please sign in to comment.