Commit 9a666c18 authored by catch's avatar catch

Issue #2899014 by drunken monkey, Dinesh18, tstoeckler: Config entity query IS...

Issue #2899014 by drunken monkey, Dinesh18, tstoeckler: Config entity query IS NOT NULL  conditions trigger warnings for non-scalar values
parent 9cf72c60
......@@ -154,6 +154,13 @@ protected function matchArray(array $condition, array $data, array $needs_matchi
* TRUE when matches else FALSE.
*/
protected function match(array $condition, $value) {
// "IS NULL" and "IS NOT NULL" conditions can also deal with array values,
// so we return early for them to avoid problems.
if (in_array($condition['operator'], ['IS NULL', 'IS NOT NULL'], TRUE)) {
$should_be_set = $condition['operator'] === 'IS NOT NULL';
return $should_be_set === isset($value);
}
if (isset($value)) {
// We always want a case-insensitive match.
if (!is_bool($value)) {
......@@ -183,15 +190,11 @@ protected function match(array $condition, $value) {
return strpos($value, $condition['value']) !== FALSE;
case 'ENDS_WITH':
return substr($value, -strlen($condition['value'])) === (string) $condition['value'];
case 'IS NOT NULL':
return TRUE;
case 'IS NULL':
return FALSE;
default:
throw new QueryException('Invalid condition operator.');
}
}
return $condition['operator'] === 'IS NULL';
return FALSE;
}
}
......@@ -572,6 +572,33 @@ public function testDotted() {
->condition('*.level1.level2', 41)
->execute();
$this->assertResults([]);
// Make sure that "IS NULL" and "IS NOT NULL" work correctly with
// array-valued fields/keys.
$all = ['1', '2', '3', '4', '5'];
$this->queryResults = $this->factory->get('config_query_test')
->exists('array.level1.level2')
->execute();
$this->assertResults($all);
$this->queryResults = $this->factory->get('config_query_test')
->exists('array.level1')
->execute();
$this->assertResults($all);
$this->queryResults = $this->factory->get('config_query_test')
->exists('array')
->execute();
$this->assertResults($all);
$this->queryResults = $this->factory->get('config_query_test')
->notExists('array.level1.level2')
->execute();
$this->assertResults([]);
$this->queryResults = $this->factory->get('config_query_test')
->notExists('array.level1')
->execute();
$this->assertResults([]);
$this->queryResults = $this->factory->get('config_query_test')
->notExists('array')
->execute();
$this->assertResults([]);
}
/**
......
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