Skip to content

Commit

Permalink
Reverse search and replace array's in str_replace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HeinDR authored Mar 23, 2022
1 parent da785e1 commit 01e1532
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Storage/SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 01e1532

Please sign in to comment.