Skip to content

Commit

Permalink
Fixing nested query strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed May 27, 2015
1 parent ffa8119 commit 6f3db16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private function applyOptions(RequestInterface $request, array &$options)
if (isset($options['query'])) {
$value = $options['query'];
if (is_array($value)) {
$value = http_build_query($value, null, null, PHP_QUERY_RFC3986);
$value = http_build_query($value, null, '&', PHP_QUERY_RFC3986);

This comment has been minimized.

Copy link
@boast

boast May 28, 2015

$value = http_build_query($value, null, ini_get('arg_separator.output') ?: '&', PHP_QUERY_RFC3986);

Is properly resetting the separator, see http://www.reddit.com/r/PHP/comments/37klg6/is_this_weird_http_build_query/

}
if (!is_string($value)) {
throw new Iae('query must be a string or array');
Expand Down
9 changes: 9 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,13 @@ public function testCanSetCustomHandler()
])->getStatusCode()
);
}

public function testProperlyBuildsQuery()
{
$mock = new MockHandler([new Response(200)]);
$client = new Client(['handler' => $mock]);
$request = new Request('PUT', 'http://foo.com');
$client->send($request, ['query' => ['foo' => 'bar', 'john' => 'doe']]);
$this->assertEquals('foo=bar&john=doe', $mock->getLastRequest()->getUri()->getQuery());
}
}

0 comments on commit 6f3db16

Please sign in to comment.