Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid dependency on ext-filter #279

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DnsConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function connect($uri)
$connector = $this->connector;

// skip DNS lookup / URI manipulation if this URI already contains an IP
if (false !== \filter_var($host, \FILTER_VALIDATE_IP)) {
if (@\inet_pton($host) !== false) {
return $connector->connect($original);
}

Expand Down
2 changes: 1 addition & 1 deletion src/HappyEyeBallsConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function connect($uri)
$host = \trim($parts['host'], '[]');

// skip DNS lookup / URI manipulation if this URI already contains an IP
if (false !== \filter_var($host, \FILTER_VALIDATE_IP)) {
if (@\inet_pton($host) !== false) {
return $this->connector->connect($original);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TcpConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function connect($uri)
}

$ip = \trim($parts['host'], '[]');
if (false === \filter_var($ip, \FILTER_VALIDATE_IP)) {
if (@\inet_pton($ip) === false) {
return Promise\reject(new \InvalidArgumentException(
'Given URI "' . $uri . '" does not contain a valid host IP (EINVAL)',
\defined('SOCKET_EINVAL') ? \SOCKET_EINVAL : 22
Expand Down
2 changes: 1 addition & 1 deletion src/TcpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function __construct($uri, LoopInterface $loop = null, array $context = a
);
}

if (false === \filter_var(\trim($parts['host'], '[]'), \FILTER_VALIDATE_IP)) {
if (@\inet_pton(\trim($parts['host'], '[]')) === false) {
throw new \InvalidArgumentException(
'Given URI "' . $uri . '" does not contain a valid host IP (EINVAL)',
\defined('SOCKET_EINVAL') ? \SOCKET_EINVAL : 22
Expand Down
10 changes: 5 additions & 5 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()

$ip = Block\await($this->request('dual.tlund.se', $connector), $loop, self::TIMEOUT);

$this->assertSame($ip, filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6), $ip);
$this->assertNotFalse(inet_pton($ip));
}

/**
Expand All @@ -110,8 +110,8 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
throw $e;
}

$this->assertSame($ip, filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4), $ip);
$this->assertFalse(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6), $ip);
$this->assertNotFalse(inet_pton($ip));
$this->assertEquals(4, strlen(inet_pton($ip)));
}

/**
Expand All @@ -131,8 +131,8 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP()
throw $e;
}

$this->assertFalse(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4), $ip);
$this->assertSame($ip, filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6), $ip);
$this->assertNotFalse(inet_pton($ip));
$this->assertEquals(16, strlen(inet_pton($ip)));
}

public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpConnectionToServer()
Expand Down