diff --git a/src/Uri.php b/src/Uri.php index f58345368..182067e35 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -1007,7 +1007,7 @@ public static function encodePath($path) )); } - $regex = '/(?:[^' . self::CHAR_UNRESERVED . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/'; + $regex = '/(?:[^' . self::CHAR_UNRESERVED . ')(:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/'; $escaper = static::getEscaper(); $replace = function ($match) use ($escaper) { return $escaper->escapeUrl($match[0]); diff --git a/test/UriTest.php b/test/UriTest.php index f7409f535..f99348eb7 100644 --- a/test/UriTest.php +++ b/test/UriTest.php @@ -1360,4 +1360,14 @@ public function testParseTwice() $this->assertNull($uri->getQuery()); $this->assertNull($uri->getFragment()); } + + public function testReservedCharsInPathUnencoded() + { + $uri = new Uri(); + $uri->setScheme('https'); + $uri->setHost('api.linkedin.com'); + $uri->setPath('/v1/people/~:(first-name,last-name,email-address,picture-url)'); + + $this->assertSame('https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address,picture-url)', $uri->toString()); + } }