Skip to content
Snippets Groups Projects
Unverified Commit 087f05e2 authored by JonGold's avatar JonGold
Browse files

fix using REGEXP with contact ID

parent 99d3046f
Branches
Tags
No related merge requests found
......@@ -126,7 +126,8 @@ class FormattingUtil {
}
// Special handling for 'current_user' and user lookups
if ($fk === 'Contact' && isset($value) && !is_numeric($value)) {
$exactMatch = [NULL, '=', '!=', '<>', 'IN', 'NOT IN'];
if ($fk === 'Contact' && isset($value) && !is_numeric($value) && in_array($operator, $exactMatch, TRUE)) {
$value = \_civicrm_api3_resolve_contactID($value);
if ('unknown-user' === $value) {
throw new \CRM_Core_Exception("\"{$fieldSpec['name']}\" \"{$value}\" cannot be resolved to a contact ID", 2002, ['error_field' => $fieldSpec['name'], "type" => "integer"]);
......
......@@ -318,6 +318,13 @@ class ContactGetTest extends Api4TestBase implements TransactionalInterface {
$this->assertArrayHasKey($meg['id'], (array) $result);
$this->assertArrayHasKey($jess['id'], (array) $result);
$this->assertArrayHasKey($amy['id'], (array) $result);
// Check that punctuation in REGEXP isn't munged away.
$findByIDs = '^(' . $jane['id'] . '|' . $meg['id'] . '|' . $jess['id'] . '|' . $amy['id'] . ')$';
$result = Contact::get(FALSE)
->addWhere('id', 'REGEXP', $findByIDs)
->execute();
$this->assertCount(4, $result);
}
public function testGetRelatedWithSubType(): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment