From 2cb5e126ee98339f552236d27a273648423bb76d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 14 Jul 2017 13:27:56 +0700 Subject: [PATCH 1/2] Fixes #13 : reserved characters in path should be unencoded --- src/Uri.php | 2 +- test/UriTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Uri.php b/src/Uri.php index 1cd292ad3..1c565c945 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 633b71a16..94780f6f6 100644 --- a/test/UriTest.php +++ b/test/UriTest.php @@ -1346,4 +1346,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()); + } } From c6fe65bb7e08b0afa36723b807d3c50850e78e49 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 18 Aug 2017 09:51:21 +0700 Subject: [PATCH 2/2] using )( same as suggested at https://github.com/zendframework/zend-diactoros/pull/258#discussion_r133827724 --- src/Uri.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Uri.php b/src/Uri.php index 1c565c945..dd98e4a33 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]);