From a9787174498f8bb214a420ab5a7f9be1e739adb5 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Thu, 7 Jan 2016 11:07:15 +0000 Subject: [PATCH] Return empty JSON array on empty query --- include/ajax.orgs.php | 5 ++++- include/ajax.tickets.php | 5 ++++- include/ajax.users.php | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/ajax.orgs.php b/include/ajax.orgs.php index f7be2b2d1..1a1c8d19c 100644 --- a/include/ajax.orgs.php +++ b/include/ajax.orgs.php @@ -24,7 +24,10 @@ class OrgsAjaxAPI extends AjaxController { if(!isset($_REQUEST['q'])) { Http::response(400, 'Query argument is required'); - } + } + + if (!$_REQUEST['q']) + return $this->json_encode(array()); $q = $_REQUEST['q']; $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 6acae0719..c20abba7e 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -26,14 +26,17 @@ class TicketsAjaxAPI extends AjaxController { function lookup() { global $thisstaff; - $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; $tickets=array(); + // Bail out of query is empty + if (!$_REQUEST['q']) + return $this->json_encode($tickets); $visibility = Q::any(array( 'staff_id' => $thisstaff->getId(), 'team_id__in' => $thisstaff->teams->values_flat('team_id'), )); + if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts())) { $visibility->add(array('dept_id__in' => $depts)); } diff --git a/include/ajax.users.php b/include/ajax.users.php index 22257675d..f8b9b78b4 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -29,6 +29,10 @@ class UsersAjaxAPI extends AjaxController { Http::response(400, __('Query argument is required')); } + $matches = array(); + if (!$_REQUEST['q']) + return $this->json_encode($matches); + $q = $_REQUEST['q']; $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; $users=array(); -- GitLab