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/4] 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/4] 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]); From 70ca1b30e14a84f64a5d86af5ff74481c25dbb50 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 10 Apr 2018 11:59:05 -0500 Subject: [PATCH 3/4] Reflows long line --- test/UriTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/UriTest.php b/test/UriTest.php index f99348eb7..4d467d9c0 100644 --- a/test/UriTest.php +++ b/test/UriTest.php @@ -1368,6 +1368,9 @@ public function testReservedCharsInPathUnencoded() $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()); + $this->assertSame( + 'https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address,picture-url)', + $uri->toString() + ); } } From c43bce63fe804f529a657f13be89d540a54d54e0 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 10 Apr 2018 12:03:11 -0500 Subject: [PATCH 4/4] Adds CHANGELOG entry for #17 --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc74d610..ed77a356b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#17](https://github.com/zendframework/zend-uri/pull/17) updates the path + encoding algorithm to allow `(` and `)` characters as path characters (per + the RFC-3986, these are valid sub-delimiters allowed within a path). ## 2.5.2 - 2016-02-17