Index: tests/Zend/Uri/HttpTest.php =================================================================== --- tests/Zend/Uri/HttpTest.php (revision 23900) +++ tests/Zend/Uri/HttpTest.php (working copy) @@ -430,4 +430,19 @@ ), $uri->getQueryAsArray()); $this->assertEquals('a=1&c=3', $uri->getQuery()); } + + /** + * @group ZF-11188 + * @see http://www.ietf.org/rfc/rfc2732.txt + */ + public function testParserSupportsLiteralIpv6AddressesInUri() + { + $this->assertTrue(Zend_Uri_Http::fromString('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html')->valid()); + $this->assertTrue(Zend_Uri_Http::fromString('http://[1080:0:0:0:8:800:200C:417A]/index.html')->valid()); + $this->assertTrue(Zend_Uri_Http::fromString('http://[3ffe:2a00:100:7031::1]')->valid()); + $this->assertTrue(Zend_Uri_Http::fromString('http://[1080::8:800:200C:417A]/foo')->valid()); + $this->assertTrue(Zend_Uri_Http::fromString('http://[::192.9.5.5]/ipng')->valid()); + $this->assertTrue(Zend_Uri_Http::fromString('http://[::FFFF:129.144.52.38]:80/index.html')->valid()); + $this->assertTrue(Zend_Uri_Http::fromString('http://[2010:836B:4179::836B:4179]')->valid()); + } } \ No newline at end of file Index: library/Zend/Uri/Http.php =================================================================== --- library/Zend/Uri/Http.php (revision 23900) +++ library/Zend/Uri/Http.php (working copy) @@ -217,24 +217,20 @@ // Additional decomposition to get username, password, host, and port $combo = isset($matches[3]) === true ? $matches[3] : ''; - $pattern = '~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~'; + $pattern = '~^(([^:@]*)(:([^@]*))?@)?((?(?=[[])[[][^]]+[]]|[^:]+))(:(.*))?$~'; $status = @preg_match($pattern, $combo, $matches); if ($status === false) { require_once 'Zend/Uri/Exception.php'; throw new Zend_Uri_Exception('Internal error: authority decomposition failed'); } - - // Failed decomposition; no further processing needed - if ($status === false) { - return; - } - + // Save remaining URI components $this->_username = isset($matches[2]) === true ? $matches[2] : ''; $this->_password = isset($matches[4]) === true ? $matches[4] : ''; - $this->_host = isset($matches[5]) === true ? $matches[5] : ''; + $this->_host = isset($matches[5]) === true + ? preg_replace('~^\[([^]]+)\]$~', '\1', $matches[5]) // Strip wrapper [] from IPv6 literal + : ''; $this->_port = isset($matches[7]) === true ? $matches[7] : ''; - } /**