Skip to content

Commit

Permalink
Fix support for array query parameters
Browse files Browse the repository at this point in the history
fixes #177
  • Loading branch information
aschempp committed Jul 28, 2020
1 parent 8e695e4 commit 295cf39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ protected function createUrlParameterBag(array $queryParameters = [])
parse_str($_SERVER['QUERY_STRING'], $currentQuery);

foreach ($input as $k => $value) {
$value = (string) Input::get($k, false, true);
// GET parameters can be an array
$value = Input::get($k, false, true);

if ('' === $value) {
if (empty($value)) {
continue;
}

if (!array_key_exists($k, $currentQuery)) {
$attributes[$k] = $value;
$attributes[$k] = (string) $value;
} elseif (\in_array($k, $queryParameters, false)) {
$query[$k] = $value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ public function testGenerateMultipleQuery()
$this->assertSame('foo=bar&bar=baz', $bag->generateQueryString());
}

public function testGenerateArrayQuery()
{
$bag = new UrlParameterBag([], ['foo' => ['bar', 'baz']]);

$this->assertSame(rawurlencode('foo[0]').'=bar&'.rawurlencode('foo[1]').'=baz', $bag->generateQueryString());
}

public function testReturnsNullOnEmptyQuery()
{
$bag = new UrlParameterBag();
Expand Down

0 comments on commit 295cf39

Please sign in to comment.