From 2f6966aa9b183a50fbc86057a41a04149de242d5 Mon Sep 17 00:00:00 2001 From: Mathias Verraes Date: Mon, 19 Jan 2015 14:34:34 +0100 Subject: [PATCH 1/4] Proof that Request::fromString() ignores query parameters --- tests/ZendTest/Http/RequestTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/ZendTest/Http/RequestTest.php b/tests/ZendTest/Http/RequestTest.php index ad4ee381322..cf7a3dc93e3 100644 --- a/tests/ZendTest/Http/RequestTest.php +++ b/tests/ZendTest/Http/RequestTest.php @@ -17,11 +17,12 @@ class RequestTest extends \PHPUnit_Framework_TestCase { public function testRequestFromStringFactoryCreatesValidRequest() { - $string = "GET /foo HTTP/1.1\r\n\r\nSome Content"; + $string = "GET /foo?myparam=myvalue HTTP/1.1\r\n\r\nSome Content"; $request = Request::fromString($string); $this->assertEquals(Request::METHOD_GET, $request->getMethod()); - $this->assertEquals('/foo', $request->getUri()); + $this->assertEquals('/foo?myparam=myvalue', $request->getUri()); + $this->assertEquals('myvalue', $request->getQuery()->get('myparam')); $this->assertEquals(Request::VERSION_11, $request->getVersion()); $this->assertEquals('Some Content', $request->getContent()); } From 59bf6b137f9d117cdfea454f5b19a225d46427cc Mon Sep 17 00:00:00 2001 From: Mathias Verraes Date: Mon, 19 Jan 2015 14:43:47 +0100 Subject: [PATCH 2/4] Fixed: Request::fromString() ignored query parameters --- library/Zend/Http/Request.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/Zend/Http/Request.php b/library/Zend/Http/Request.php index 9e53ac2ec95..ca571fddf75 100644 --- a/library/Zend/Http/Request.php +++ b/library/Zend/Http/Request.php @@ -93,6 +93,13 @@ public static function fromString($string) $request->setMethod($matches['method']); $request->setUri($matches['uri']); + $parsedUri = parse_url($matches['uri']); + if(array_key_exists('query', $parsedUri)) { + $parsedQuery = []; + parse_str($parsedUri['query'], $parsedQuery); + $request->setQuery(new Parameters($parsedQuery)); + } + if (isset($matches['version'])) { $request->setVersion($matches['version']); } From f5755f0a2a9785415a6110d333a701cd7a44e0e5 Mon Sep 17 00:00:00 2001 From: Mathias Verraes Date: Mon, 19 Jan 2015 15:24:26 +0100 Subject: [PATCH 3/4] [] compatibility fix --- library/Zend/Http/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Zend/Http/Request.php b/library/Zend/Http/Request.php index ca571fddf75..0452073a71d 100644 --- a/library/Zend/Http/Request.php +++ b/library/Zend/Http/Request.php @@ -95,7 +95,7 @@ public static function fromString($string) $parsedUri = parse_url($matches['uri']); if(array_key_exists('query', $parsedUri)) { - $parsedQuery = []; + $parsedQuery = array(); parse_str($parsedUri['query'], $parsedQuery); $request->setQuery(new Parameters($parsedQuery)); } From e8cc3bf391c172c2dbbcd4df3da3d3330ba1dbba Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 19 Jan 2015 19:56:02 +0100 Subject: [PATCH 4/4] #7137 #7005 - CS fix (space between `if` and `(`) --- library/Zend/Http/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Zend/Http/Request.php b/library/Zend/Http/Request.php index 0452073a71d..1c8956a353a 100644 --- a/library/Zend/Http/Request.php +++ b/library/Zend/Http/Request.php @@ -94,7 +94,7 @@ public static function fromString($string) $request->setUri($matches['uri']); $parsedUri = parse_url($matches['uri']); - if(array_key_exists('query', $parsedUri)) { + if (array_key_exists('query', $parsedUri)) { $parsedQuery = array(); parse_str($parsedUri['query'], $parsedQuery); $request->setQuery(new Parameters($parsedQuery));