diff --git a/src/Client.php b/src/Client.php index 2d1ecb7..a681fe1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -141,11 +141,11 @@ public function connect($uri) // append hostname from URI to query string unless explicitly given if (!isset($args['hostname'])) { - $args['hostname'] = $parts['host']; + $args['hostname'] = $host; } // append query string - $socksUri .= '?' . http_build_query($args, '', '&');; + $socksUri .= '?' . http_build_query($args, '', '&'); // append fragment from URI if given if (isset($parts['fragment'])) { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 615e51c..0d179ef 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -262,6 +262,24 @@ public function testEmitSocks5DataInvalidAddressTypeWillRejectConnection() $promise->then(null, $this->expectCallableOnceWithExceptionCode(SOCKET_EBADMSG)); } + public function testEmitSocks5DataIpv6AddressWillResolveConnection() + { + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock(); + $stream->expects($this->never())->method('close'); + + $promise = \React\Promise\resolve($stream); + + $this->connector->expects($this->once())->method('connect')->with('127.0.0.1:1080?hostname=%3A%3A1')->willReturn($promise); + + $this->client = new Client('socks5://127.0.0.1:1080', $this->connector); + + $promise = $this->client->connect('[::1]:80'); + + $stream->emit('data', array("\x05\x00" . "\x05\x00\x00\x04" . inet_pton('::1') . "\x00\x50")); + + $promise->then($this->expectCallableOnce()); + } + public function testEmitSocks5DataHostnameAddressWillResolveConnection() { $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();