Skip to content

Commit ead9efb

Browse files
authored
Merge pull request #279 from clue-labs/no-filter
Avoid dependency on `ext-filter`
2 parents d132fde + 28bd075 commit ead9efb

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/DnsConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function connect($uri)
3939
$connector = $this->connector;
4040

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

src/HappyEyeBallsConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function connect($uri)
5050
$host = \trim($parts['host'], '[]');
5151

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

src/TcpConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function connect($uri)
3434
}
3535

3636
$ip = \trim($parts['host'], '[]');
37-
if (false === \filter_var($ip, \FILTER_VALIDATE_IP)) {
37+
if (@\inet_pton($ip) === false) {
3838
return Promise\reject(new \InvalidArgumentException(
3939
'Given URI "' . $uri . '" does not contain a valid host IP (EINVAL)',
4040
\defined('SOCKET_EINVAL') ? \SOCKET_EINVAL : 22

src/TcpServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function __construct($uri, LoopInterface $loop = null, array $context = a
160160
);
161161
}
162162

163-
if (false === \filter_var(\trim($parts['host'], '[]'), \FILTER_VALIDATE_IP)) {
163+
if (@\inet_pton(\trim($parts['host'], '[]')) === false) {
164164
throw new \InvalidArgumentException(
165165
'Given URI "' . $uri . '" does not contain a valid host IP (EINVAL)',
166166
\defined('SOCKET_EINVAL') ? \SOCKET_EINVAL : 22

tests/FunctionalConnectorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()
9090

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

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

9696
/**
@@ -110,8 +110,8 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
110110
throw $e;
111111
}
112112

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

117117
/**
@@ -131,8 +131,8 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP()
131131
throw $e;
132132
}
133133

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

138138
public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpConnectionToServer()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy