From 01e1532be7208cd3577f98234227d0d827a96fa4 Mon Sep 17 00:00:00 2001 From: Hein Date: Wed, 23 Mar 2022 10:55:55 +0100 Subject: [PATCH] Reverse search and replace array's in str_replace The parameters in the search array are appended with an index number. This causes problems when the elements in the array exceed 10 because the first element will find a part in the 10th element (e.g. `content.topics = :topics_1` and `content.topics = :topics_10`). The resulting query will be corrupted because the 0 (in case of the 10th element) will not be replaced and left dangling in the string. This change fixes this by reversing the array's, so the largest string will be looked up and replaced first. --- src/Storage/SelectQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/SelectQuery.php b/src/Storage/SelectQuery.php index 510a7d217..2b9f9ac12 100644 --- a/src/Storage/SelectQuery.php +++ b/src/Storage/SelectQuery.php @@ -604,7 +604,7 @@ private function getRegularFieldWhereExpression(Filter $filter, string $valueAli return sprintf("JSON_SEARCH(%s, 'one', %s) != ''", $valueAlias, $parameter[0]); }, $expressions); - return str_replace($expressions, $newExpressions, $filter->getExpression()); + return str_replace(array_reverse($expressions), array_reverse($newExpressions), $filter->getExpression()); } $originalLeftExpression = 'content.' . $filter->getKey();