From: deb.monish Date: Mon, 11 Jul 2016 11:45:37 +0000 (+0530) Subject: CRM-19006: Unit test to assert special characters in custom value X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e5ccf3d9d8b8c4af3d9c40b6aeb3881046cc77ce;p=civicrm-core.git CRM-19006: Unit test to assert special characters in custom value --- diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index ce3586a5fa..ab510d164b 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -348,7 +348,7 @@ SELECT f.id, f.label, f.data_type, // CRM-19006: escape characters like comma, | before building regex pattern $value = (array) $value; foreach ($value as $key => $val) { - $value[$key] = str_replace(array('|', '[', ']', ','), array('\|', '\[', '\]', '[:comma:]'), $val); + $value[$key] = str_replace(array('|', '[', ']', ','), array('[:spearator:]', '\[', '\]', '[:comma:]'), $val); } $value = implode(',', $value); } @@ -364,10 +364,12 @@ SELECT f.id, f.label, f.data_type, $value = $sp . $value . $sp; if (!$wildcard) { foreach (explode("|", $value) as $val) { + $val = str_replace('[:separator:]', '\|', $val); $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $val, 'String'); } } else { + $value = str_replace('[:separator:]', '\|', $value); $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'String'); } } diff --git a/tests/phpunit/api/v3/CustomValueTest.php b/tests/phpunit/api/v3/CustomValueTest.php index 3d7764132e..6e63b6e798 100644 --- a/tests/phpunit/api/v3/CustomValueTest.php +++ b/tests/phpunit/api/v3/CustomValueTest.php @@ -44,7 +44,7 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { $dataValues = array( 'integer' => array(1, 2, 3), 'number' => array(10.11, 20.22, 30.33), - 'string' => array(substr(sha1(rand()), 0, 4), substr(sha1(rand()), 0, 3), substr(sha1(rand()), 0, 2)), + 'string' => array(substr(sha1(rand()), 0, 4) . '(', substr(sha1(rand()), 0, 3) . '|', substr(sha1(rand()), 0, 2) . ','), // 'country' => array_rand(CRM_Core_PseudoConstant::country(FALSE, FALSE), 3), // This does not work in the test at the moment due to caching issues. //'state_province' => array_rand(CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE), 3),