Skip to content

Commit 496d392

Browse files
committed
Fix adding port to IPv6 addresses
1 parent 51dccf8 commit 496d392

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/React/Dns/Resolver/Factory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ protected function createCachedExecutor(LoopInterface $loop)
4646

4747
protected function addPortToServerIfMissing($nameserver)
4848
{
49-
return false === strpos($nameserver, ':') ? "$nameserver:53" : $nameserver;
49+
$colon = strrpos($nameserver, ':');
50+
51+
// there is no colon at all or the last one does not have a closing IPv6 bracket right before it
52+
if ($colon === false || (strpos($nameserver, ':') !== $colon && strpos($nameserver, ']') !== ($colon - 1))) {
53+
if (strpos($nameserver, ':') !== $colon) {
54+
// several colons => enclose IPv6 address in square brackets
55+
$nameserver = '[' . $nameserver . ']';
56+
}
57+
$nameserver .= ':53';
58+
}
59+
return $nameserver;
5060
}
5161
}

0 commit comments

Comments
 (0)