From 05d252047992d7dcf658f5efa3fad9b054efb61f Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Wed, 20 Nov 2013 14:43:15 +0100 Subject: [PATCH] fixes a regression introduced in recent versions --- src/Guzzle/Http/Url.php | 17 +++++++++++++++-- tests/Guzzle/Tests/Http/ClientTest.php | 6 +++--- tests/Guzzle/Tests/Http/UrlTest.php | 4 +++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Guzzle/Http/Url.php b/src/Guzzle/Http/Url.php index dc33aaf9..62437f6f 100644 --- a/src/Guzzle/Http/Url.php +++ b/src/Guzzle/Http/Url.php @@ -518,7 +518,7 @@ class Url if (!$path) { if (count($query)) { - $this->query = $query; + $this->addQuery($query, $strictRfc386); } } else { if ($path[0] == '/') { @@ -529,11 +529,24 @@ class Url $this->path .= '/' . $path; } $this->normalizePath(); - $this->query = $query; + $this->addQuery($query, $strictRfc386); } $this->fragment = $url->getFragment(); return $this; } + + private function addQuery(QueryString $new, $strictRfc386) + { + if ($strictRfc386) { + $this->query = $new; + + return; + } + + foreach ($new as $k => $v) { + $this->query->add($k, $v); + } + } } diff --git a/tests/Guzzle/Tests/Http/ClientTest.php b/tests/Guzzle/Tests/Http/ClientTest.php index d70b0119..496b21df 100644 --- a/tests/Guzzle/Tests/Http/ClientTest.php +++ b/tests/Guzzle/Tests/Http/ClientTest.php @@ -244,9 +244,9 @@ class ClientTest extends \Guzzle\Tests\GuzzleTestCase array($u, 'relative/path/to/resource?a=b&c=d', $u . 'relative/path/to/resource?a=b&c=d'), array($u, '/absolute/path/to/resource', $this->getServer()->getUrl() . 'absolute/path/to/resource'), array($u, '/absolute/path/to/resource?a=b&c=d', $this->getServer()->getUrl() . 'absolute/path/to/resource?a=b&c=d'), - array($u2, '/absolute/path/to/resource?a=b&c=d', $this->getServer()->getUrl() . 'absolute/path/to/resource?a=b&c=d'), - array($u2, 'relative/path/to/resource', $this->getServer()->getUrl() . 'base/relative/path/to/resource'), - array($u2, 'relative/path/to/resource?another=query', $this->getServer()->getUrl() . 'base/relative/path/to/resource?another=query') + array($u2, '/absolute/path/to/resource?a=b&c=d', $this->getServer()->getUrl() . 'absolute/path/to/resource?z=1&a=b&c=d'), + array($u2, 'relative/path/to/resource', $this->getServer()->getUrl() . 'base/relative/path/to/resource?z=1'), + array($u2, 'relative/path/to/resource?another=query', $this->getServer()->getUrl() . 'base/relative/path/to/resource?z=1&another=query') ); } diff --git a/tests/Guzzle/Tests/Http/UrlTest.php b/tests/Guzzle/Tests/Http/UrlTest.php index 4da8eb08..c1a57bd7 100644 --- a/tests/Guzzle/Tests/Http/UrlTest.php +++ b/tests/Guzzle/Tests/Http/UrlTest.php @@ -154,7 +154,9 @@ class UrlTest extends \Guzzle\Tests\GuzzleTestCase array('http://u:a@www.example.com/path', 'test', 'http://u:a@www.example.com/path/test'), array('http://www.example.com/path', 'http://u:a@www.example.com/', 'http://u:a@www.example.com/'), array('/path?q=2', 'http://www.test.com/', 'http://www.test.com/path?q=2'), - array('http://api.flickr.com/services/', 'http://www.flickr.com/services/oauth/access_token', 'http://www.flickr.com/services/oauth/access_token') + array('http://api.flickr.com/services/', 'http://www.flickr.com/services/oauth/access_token', 'http://www.flickr.com/services/oauth/access_token'), + array('http://www.example.com/?foo=bar', 'some/path', 'http://www.example.com/some/path?foo=bar'), + array('http://www.example.com/?foo=bar', 'some/path?boo=moo', 'http://www.example.com/some/path?foo=bar&boo=moo'), ); }