mirror of
https://github.com/predis/predis.git
synced 2026-08-28 11:09:49 +00:00
Strip brackets from host when parsing embedded IPv6 address.
I don't know why PHP's parse_url() does not do that, it does not make sense when the IP is by itself so maybe it is a bug?
This commit is contained in:
@@ -88,6 +88,14 @@ class Parameters implements ParametersInterface
|
||||
throw new \InvalidArgumentException("Invalid parameters URI: $uri");
|
||||
}
|
||||
|
||||
if (
|
||||
isset($parsed['host'])
|
||||
&& false !== strpos($parsed['host'], '[')
|
||||
&& false !== strpos($parsed['host'], ']')
|
||||
) {
|
||||
$parsed['host'] = substr($parsed['host'], 1, -1);
|
||||
}
|
||||
|
||||
if (isset($parsed['query'])) {
|
||||
parse_str($parsed['query'], $queryarray);
|
||||
unset($parsed['query']);
|
||||
@@ -121,6 +129,14 @@ class Parameters implements ParametersInterface
|
||||
throw new \InvalidArgumentException("Invalid parameters URI: $uri");
|
||||
}
|
||||
|
||||
if (
|
||||
isset($parsed['host'])
|
||||
&& false !== strpos($parsed['host'], '[')
|
||||
&& false !== strpos($parsed['host'], ']')
|
||||
) {
|
||||
$parsed['host'] = substr($parsed['host'], 1, -1);
|
||||
}
|
||||
|
||||
if (isset($parsed['query'])) {
|
||||
parse_str($parsed['query'], $queryarray);
|
||||
unset($parsed['query']);
|
||||
|
||||
@@ -260,6 +260,22 @@ class ParametersTest extends PredisTestCase
|
||||
$this->assertSame($expected, Parameters::parse($uri));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParsingURIWithEmbeddedIPV6AddressShouldStripBracketsFromHost()
|
||||
{
|
||||
$uri = 'tcp://[::1]:7000';
|
||||
|
||||
$expected = array(
|
||||
'scheme' => 'tcp',
|
||||
'host' => '::1',
|
||||
'port' => 7000,
|
||||
);
|
||||
|
||||
$this->assertSame($expected, Parameters::parse($uri));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @expectedException \InvalidArgumentException
|
||||
|
||||
Reference in New Issue
Block a user