diff --git a/src/Uri.php b/src/Uri.php index 6e12c3f9c..744b62797 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -253,6 +253,20 @@ public function isAbsolute() return ($this->scheme !== null); } + /** + * Reset URI parts + */ + protected function reset() + { + $this->setScheme(null); + $this->setPort(null); + $this->setUserInfo(null); + $this->setHost(null); + $this->setPath(null); + $this->setFragment(null); + $this->setQuery(null); + } + /** * Parse a URI string * @@ -261,6 +275,8 @@ public function isAbsolute() */ public function parse($uri) { + $this->reset(); + // Capture scheme if (($scheme = self::parseScheme($uri)) !== null) { $this->setScheme($scheme); diff --git a/test/UriTest.php b/test/UriTest.php index 87d893de6..de20b69ff 100644 --- a/test/UriTest.php +++ b/test/UriTest.php @@ -1335,4 +1335,18 @@ public function notStringInputProvider() array(array('scheme' => 'http', 'host' => 'example.com')) ); } + + public function testParseTwice() + { + $uri = new Uri(); + $uri->parse('http://user@example.com:1/absolute/url?query#fragment'); + $uri->parse('/relative/url'); + $this->assertNull($uri->getScheme()); + $this->assertNull($uri->getHost()); + $this->assertNull($uri->getUserInfo()); + $this->assertNull($uri->getPort()); + $this->assertNull($uri->getQuery()); + $this->assertNull($uri->getFragment()); + } + }