From fdbc0f2e8d4b58bf20a19970897d5597f5fe454f Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 20 Jul 2021 13:14:30 +1200 Subject: [PATCH] Add test for failing OR clause This fails because when the field is being concatenated like `a`.`first_name`='x' OR`a`.`last_name`='x' The lack of a space between OR and `a` is fugly but it is parsed by mysql. However, when the value requires utf8mb4 to be supported to do the comparison it returns '0=1' if the database does not support utf8mb (or it thinks it doesn't per 0 = 1 OR0 = 1 --- Civi/Api4/Query/Api4SelectQuery.php | 2 +- tests/phpunit/api/v4/Action/ContactGetTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Civi/Api4/Query/Api4SelectQuery.php b/Civi/Api4/Query/Api4SelectQuery.php index 5a7e75d50f..64d94ed4c2 100644 --- a/Civi/Api4/Query/Api4SelectQuery.php +++ b/Civi/Api4/Query/Api4SelectQuery.php @@ -396,7 +396,7 @@ class Api4SelectQuery { foreach ($clause[1] as $subclause) { $sql_subclauses[] = $this->treeWalkClauses($subclause, $type, $depth + 1); } - return '(' . implode("\n" . $clause[0], $sql_subclauses) . ')'; + return '(' . implode("\n" . $clause[0] . ' ', $sql_subclauses) . ')'; } case 'NOT': diff --git a/tests/phpunit/api/v4/Action/ContactGetTest.php b/tests/phpunit/api/v4/Action/ContactGetTest.php index c8cafd824d..f48e4d2882 100644 --- a/tests/phpunit/api/v4/Action/ContactGetTest.php +++ b/tests/phpunit/api/v4/Action/ContactGetTest.php @@ -259,4 +259,14 @@ class ContactGetTest extends \api\v4\UnitTestCase { $this->assertEquals(['Student'], $result['Contact_RelationshipCache_Contact_01.contact_sub_type:label']); } + /** + * @throws \API_Exception + */ + public function testOrClause(): void { + Contact::get() + ->addClause('OR', ['first_name', '=', '🚂'], ['last_name', '=', '🚂']) + ->setCheckPermissions(FALSE) + ->execute(); + } + } -- 2.25.1