Skip to content

Commit

Permalink
Merge pull request #9412 from seamuslee001/CRM-19562-46
Browse files Browse the repository at this point in the history
CRM-19562
  • Loading branch information
eileenmcnaughton committed Nov 19, 2016
2 parents 5f8f450 + 4749764 commit a5e4c06
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CRM/Contact/BAO/Query.php
Expand Up @@ -3500,6 +3500,7 @@ public function includeContactIDs() {
$contactIds[] = substr($values[0], CRM_Core_Form::CB_PREFIX_LEN);
}
}
CRM_Utils_Type::validateAll($contactIds, 'Positive');
if (!empty($contactIds)) {
$this->_where[0][] = " ( contact_a.id IN (" . implode(',', $contactIds) . " ) ) ";
}
Expand Down
12 changes: 12 additions & 0 deletions CRM/Utils/Type.php
Expand Up @@ -299,6 +299,18 @@ public static function escape($data, $type, $abort = TRUE) {
return NULL;
}

/**
* Helper function to call validate on arrays
*
* @see validate
*/
public static function validateAll($data, $type, $abort = TRUE) {
foreach ($data as $key => $value) {
$data[$key] = CRM_Utils_Type::validate($value, $type, $abort);
}
return $data;
}

/**
* Verify that a variable is of a given type.
*
Expand Down
30 changes: 30 additions & 0 deletions tests/phpunit/CRM/Contact/BAO/QueryTest.php
Expand Up @@ -191,4 +191,34 @@ public function testSearchProfilePrimaryCityCRM14263() {
}
}

/**
* CRM-19562 ensure that only ids are used for contactid searching.
*/
public function testContactIDClause() {
$params = array(
array("mark_x_2", "=", 1, 0, 0),
array("mark_x_foo@example.com", "=", 1, 0, 0),
);
$returnProperties = array(
"sort_name" => 1,
"email" => 1,
"do_not_email" => 1,
"is_deceased" => 1,
"on_hold" => 1,
"display_name" => 1,
"preferred_mail_format" => 1,
);
$numberofContacts = 2;
$query = new CRM_Contact_BAO_Query($params, $returnProperties);
try {
$query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);
}
catch (Exception $e) {
$this->assertEquals("A fatal error was triggered: One of parameters (value: foo@example.com) is not of the type Positive",
$e->getMessage());
return $this->assertTrue(TRUE);
}
return $this->fail('Test failed for some reason which is not good');
}

}

0 comments on commit a5e4c06

Please sign in to comment.