Skip to content

Commit d9e5a4f

Browse files
committed
Merge pull request #6 from WyriHaximus/patch-2
Swapped needle and haystack arguments
2 parents 2e81893 + d0ff285 commit d9e5a4f

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/Socket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ private function sanitizeAddress($address)
104104
{
105105
// doc comment suggests IPv6 address is not enclosed in square brackets?
106106
107-
$pos = strrpos(':', $address);
107+
$pos = strrpos($address, ':');
108108
// this is an IPv6 address which includes colons but no square brackets
109109
if ($pos !== false && substr($address, 0, 1) !== '[') {
110-
if (strpos(':', $address) < $pos) {
110+
if (strpos($address, ':') < $pos) {
111111
$port = substr($address, $pos + 1);
112112
$address = '[' . substr($address, 0, $pos) . ']:' . $port;
113113
}

tests/SocketTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,46 @@ public function testCreatePair()
141141

142142
$this->loop->run();
143143
}
144+
145+
public function provideSanitizeAddress()
146+
{
147+
return array(
148+
array(
149+
'127.0.0.1:1337',
150+
),
151+
array(
152+
'[::1]:1337',
153+
),
154+
);
155+
}
156+
157+
/**
158+
* @dataProvider provideSanitizeAddress
159+
*/
160+
public function testSanitizeAddress($address)
161+
{
162+
$promise = $this->factory->createServer($address);
163+
$server = $this->getValueFromResolvedPromise($promise);
164+
165+
$promise = $this->factory->createClient($server->getLocalAddress());
166+
$client = $this->getValueFromResolvedPromise($promise);
167+
168+
$that = $this;
169+
$server->on('message', function ($message, $remote, $server) use ($that) {
170+
// once the server receives a message, send it pack to client and stop server
171+
$server->send('response:' . $message, $remote);
172+
$server->end();
173+
});
174+
175+
$client->on('message', function ($message, $remote, $client) use ($that, $address) {
176+
$that->assertEquals($address, $remote);
177+
178+
// once the client receives a message, stop client
179+
$client->end();
180+
});
181+
182+
$client->send('test');
183+
184+
$this->loop->run();
185+
}
144186
}

0 commit comments

Comments
 (0)