From 4d71b82e08398dade957e12e70aa56fc0063d762 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 15 Sep 2021 13:17:04 -0400 Subject: [PATCH] SearchKit - Correctly process filters passed through Afform from javascript --- .../Action/SearchDisplay/AbstractRunAction.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index f1578097d2..66b0d2b7b9 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -429,10 +429,16 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction { if ($filterAttr && is_string($filterAttr) && $filterAttr[0] === '{') { foreach (\CRM_Utils_JS::decode($filterAttr) as $filterKey => $filterVal) { // Automatically apply filters from the markup if they have a value - // (if it's a javascript variable it will have come back from decode() as NULL and we'll ignore it). - unset($this->filters[$filterKey]); - if ($this->hasValue($filterVal)) { - $this->applyFilter(explode(',', $filterKey), $filterVal); + if ($filterVal !== NULL) { + unset($this->filters[$filterKey]); + if ($this->hasValue($filterVal)) { + $this->applyFilter(explode(',', $filterKey), $filterVal); + } + } + // If it's a javascript variable it will have come back from decode() as NULL; + // whitelist it to allow it to be passed to this api from javascript. + else { + $filterKeys[] = $filterKey; } } } -- 2.25.1