Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Host Parsing of IPv6-URI with port #12

Open
kronthto opened this issue Feb 3, 2017 · 2 comments
Open

Host Parsing of IPv6-URI with port #12

kronthto opened this issue Feb 3, 2017 · 2 comments

Comments

@kronthto
Copy link

kronthto commented Feb 3, 2017

Hi,

As you probably know IPv6 addresses with ports are wrapped in square brackets (because the colon sign also appears in the IP address itself).

These brackets are not treated (removed) in any way currently, what leads to an behaviour I didn't expect.
I'd expect getHost() to return only the IP address, without brackets, as the port is stored seperately and obtainable via getPort().

Consider this example:

$ipv4Port = new \Zend\Uri\Uri('http://192.168.0.1:8080');
$ipv6Port = new \Zend\Uri\Uri('http://[fe80::240:63ff:fede:3c19]:8080');

echo $ipv4Port->getHost(); // -> 192.168.0.1 - expected
echo $ipv6Port->getHost(); // -> [fe80::240:63ff:fede:3c19] - unexpected

Is this intended behaviour, though, or just not yet adjusted to IPv6?

@kronthto
Copy link
Author

kronthto commented Feb 4, 2017

Even further, if you have an "Non-Domain-Name IPv6 Host URI with Port" thats last segment is fully numeric it gets mistakenly interpreted its last segment as port.
Example:

var_dump(new \Zend\Uri\Uri('http://2001:0db8:0000:85a3:0000:0000:ac1f:8001/foo'));
/*
object(Zend\Uri\Uri)#3 (8) {
  ["scheme":protected]=>
  string(4) "http"
  ["host":protected]=>
  --> string(34) "2001:0db8:0000:85a3:0000:0000:ac1f"// missing :8001
  ["port":protected]=>
  --> int(8001) // no port given
  ["path":protected]=>
  string(4) "/foo"
  ["validHostTypes":protected]=>
  int(31)
  (...)
}
*/

This - I would call it bug - also happens using the stdlib function parse_url though:

var_dump(parse_url('http://2001:0db8:0000:85a3:0000:0000:ac1f:8001/foo'));
/*
array(4) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  --> string(34) "2001:0db8:0000:85a3:0000:0000:ac1f" // missing :8001
  ["port"]=>
  --> int(8001) // no port given
  ["path"]=>
  string(4) "/foo"
}
*/

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-uri; a new issue has been opened at laminas/laminas-uri#3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants