From 2009cd216688bba4ce205e13962c0280a4ffc19e Mon Sep 17 00:00:00 2001 From: fjafari Date: Fri, 30 Sep 2022 13:57:07 -0400 Subject: [PATCH] check for non associative arrays --- src/Query/AbstractQuery.php | 9 +++++++++ src/Query/BoolQuery.php | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/Query/AbstractQuery.php b/src/Query/AbstractQuery.php index d594687846..ab8a7af829 100644 --- a/src/Query/AbstractQuery.php +++ b/src/Query/AbstractQuery.php @@ -19,4 +19,13 @@ protected function _getBaseName() return Util::toSnakeCase($shortName); } + + public function isNotAssociativeArray(array $arr) + { + if ([] === $arr) { + return true; + } + + return \array_keys($arr) === \range(0, \count($arr) - 1); + } } diff --git a/src/Query/BoolQuery.php b/src/Query/BoolQuery.php index a7d56e28a6..010db25053 100644 --- a/src/Query/BoolQuery.php +++ b/src/Query/BoolQuery.php @@ -111,6 +111,10 @@ protected function _addQuery(string $type, $args): self throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery'); } + if (\is_array($args) && $this->isNotAssociativeArray($args)) { + throw new InvalidException('Invalid parameter. The array must be an associative array.'); + } + return $this->addParam($type, $args); } }