Commit 63b7ded4 authored by catch's avatar catch

Issue #2744421 by andypost, Wim Leers: QueryArgsCacheContext::getContext() may...

Issue #2744421 by andypost, Wim Leers: QueryArgsCacheContext::getContext() may return NULL, violates the interface
parent d97b4131
......@@ -25,7 +25,10 @@ public static function getLabel() {
*/
public function getContext($query_arg = NULL) {
if ($query_arg === NULL) {
return $this->requestStack->getCurrentRequest()->getQueryString();
// All arguments requested. Use normalized query string to minimize
// variations.
$value = $this->requestStack->getCurrentRequest()->getQueryString();
return ($value !== NULL) ? $value : '';
}
elseif ($this->requestStack->getCurrentRequest()->query->has($query_arg)) {
$value = $this->requestStack->getCurrentRequest()->query->get($query_arg);
......@@ -35,13 +38,9 @@ public function getContext($query_arg = NULL) {
elseif ($value !== '') {
return $value;
}
else {
return '?valueless?';
}
}
else {
return NULL;
return '?valueless?';
}
return '';
}
/**
......
......@@ -31,15 +31,15 @@ public function testGetContext(array $query_args, $cache_context_parameter, $con
*/
public function providerTestGetContext() {
return [
[[], NULL, NULL],
[[], 'foo', NULL],
[[], NULL, ''],
[[], 'foo', ''],
// Non-empty query arguments.
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], NULL, 'alpaca=&llama=rocks&panda=drools&z=0'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'llama', 'rocks'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'alpaca', '?valueless?'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'panda', 'drools'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'z', '0'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', NULL],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', ''],
[['llama' => ['rocks', 'kitty']], 'llama', '0=rocks&1=kitty'],
[['llama' => ['rocks' => 'fuzzball', 'monkey' => 'patch']], 'llama', 'rocks=fuzzball&monkey=patch'],
[['llama' => ['rocks' => ['nested', 'bonobo']]], 'llama', 'rocks%5B0%5D=nested&rocks%5B1%5D=bonobo'],
......
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