From 580e089fbdce2e6a560ed45491fb8402b9fe5938 Mon Sep 17 00:00:00 2001 From: Brienne Kordis Date: Fri, 27 May 2022 16:57:16 -0400 Subject: [PATCH] core 3459 getlist leading zero fix --- api/v3/Generic/Getlist.php | 2 +- tests/phpunit/api/v3/EventTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index af8fb61c3b..5a83a71922 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -27,7 +27,7 @@ function civicrm_api3_generic_getList($apiRequest) { $meta = civicrm_api3_generic_getfields(['action' => 'get'] + $apiRequest, FALSE)['values']; // If the user types an integer into the search - $forceIdSearch = empty($request['id']) && !empty($request['input']) && !empty($meta['id']) && CRM_Utils_Rule::positiveInteger($request['input']); + $forceIdSearch = empty($request['id']) && !empty($request['input']) && !empty($meta['id']) && CRM_Utils_Rule::positiveInteger($request['input']) && (substr($request['input'], 0, 1) !== '0'); // Add an extra page of results for the record with an exact id match if ($forceIdSearch) { $request['page_num'] = ($request['page_num'] ?? 1) - 1; diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index b66b2b0b2a..bba9dc803c 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -923,4 +923,16 @@ class api_v3_EventTest extends CiviUnitTestCase { } } + public function testGetListLeadingZero() { + $this->callAPISuccess('Event', 'create', [ + 'title' => "0765", + 'start_date' => "2022-04-04", + 'event_type_id' => "Conference", + ]); + $result = $this->callAPISuccess('Event', 'getlist', [ + 'input' => "0765", + ]); + $this->assertEquals(1, $result['count']); + } + } -- 2.25.1