diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Condition.php b/core/lib/Drupal/Core/Config/Entity/Query/Condition.php index bb20fbe..b0a325f 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/Condition.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/Condition.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Config\Entity\Query; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\Query\ConditionBase; use Drupal\Core\Entity\Query\ConditionInterface; use Drupal\Core\Entity\Query\QueryException; @@ -33,6 +34,15 @@ public function compile($configs) { if (!isset($condition['operator'])) { $condition['operator'] = is_array($condition['value']) ? 'IN' : '='; } + + // Lowercase condition value(s) for case-insensitive matches. + if (is_array($condition['value'])) { + $condition['value'] = array_map('Drupal\Component\Utility\Unicode::strtolower', $condition['value']); + } + else { + $condition['value'] = Unicode::strtolower($condition['value']); + } + $single_conditions[] = $condition; } } @@ -150,6 +160,9 @@ protected function matchArray(array $condition, array $data, array $needs_matchi */ protected function match(array $condition, $value) { if (isset($value)) { + // We always want a case-insensitive match. + $value = Unicode::strtolower($value); + switch ($condition['operator']) { case '=': return $value == $condition['value']; diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php index 9a84de9..3926f29 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php @@ -110,7 +110,7 @@ protected function setUp() { $array['level1']['level2'] = 3; $entity = entity_create('config_query_test', array( - 'label' => $this->randomName() . '_test_contains_' . $this->randomName(), + 'label' => $this->randomName() . '_TEST_contains_' . $this->randomName(), 'id' => '5', 'number' => 53, 'array' => $array, @@ -462,6 +462,22 @@ protected function testDotted() { } /** + * Tests case sensitivity. + */ + public function testCaseSensitivity() { + // Filter by label with a known containing case-sensitive word. + $this->queryResults = $this->factory->get('config_query_test') + ->condition('label', 'TEST', 'CONTAINS') + ->execute(); + $this->assertResults(array('3', '4', '5')); + + $this->queryResults = $this->factory->get('config_query_test') + ->condition('label', 'test', 'CONTAINS') + ->execute(); + $this->assertResults(array('3', '4', '5')); + } + + /** * Asserts the results as expected regardless of order. * * @param array $expected