Commit 280a968b authored by Sebastian De Deyne's avatar Sebastian De Deyne
Browse files

Handle valueless query params

parent 187ba511
......@@ -21,7 +21,9 @@ class QueryParameterBag
}
return new static(Arr::mapToAssoc(explode('&', $query), function (string $keyValue) {
return explode('=', $keyValue, 2);
$parts = explode('=', $keyValue, 2);
return count($parts) === 2 ? $parts : [$parts[0], null];
}));
}
......
......@@ -64,4 +64,20 @@ class UrlQueryParametersTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($url->hasQueryParameter('offset'));
}
/** @test */
public function it_can_handle_empty_query_parameters()
{
$url = Url::create()->withQuery('offset');
$this->assertTrue($url->hasQueryParameter('offset'));
}
/** @test */
public function empty_query_parameters_default_to_null()
{
$url = Url::create()->withQuery('offset');
$this->assertNull($url->getQueryParameter('offset'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment