Skip to content

Commit 0261ef4

Browse files
author
Luke Jones
committed
[BUG-69] fixed in clause filter
+ added trim to explode to support both 1,2,3 and 1, 2, 3 inputs + dropped in_array strict equality check to be in line with the other standard equality checks such as (== and !=)
1 parent e01ff3e commit 0261ef4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Filters/QueryMatchFilter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function filter($collection): array
5656
$comparisonValue = preg_replace('/^[\'"]/', '', $comparisonValue);
5757
$comparisonValue = preg_replace('/[\'"]$/', '', $comparisonValue);
5858
$comparisonValue = preg_replace('/[\'"],[ ]*[\'"]/', ',', $comparisonValue);
59-
$comparisonValue = explode(",", $comparisonValue);
59+
$comparisonValue = array_map('trim', explode(",", $comparisonValue));
6060
} else {
6161
$comparisonValue = preg_replace('/^[\'"]/', '', $comparisonValue);
6262
$comparisonValue = preg_replace('/[\'"]$/', '', $comparisonValue);
@@ -113,14 +113,14 @@ public function filter($collection): array
113113
$return[] = $value;
114114
}
115115

116-
if ($operator === 'in' && is_array($comparisonValue) && in_array($value1, $comparisonValue, true)) {
116+
if ($operator === 'in' && is_array($comparisonValue) && in_array($value1, $comparisonValue)) {
117117
$return[] = $value;
118118
}
119119

120120
if (
121121
($operator === 'nin' || $operator === '!in') &&
122122
is_array($comparisonValue) &&
123-
!in_array($value1, $comparisonValue, true)
123+
!in_array($value1, $comparisonValue)
124124
) {
125125
$return[] = $value;
126126
}

tests/QueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ public function queryDataProvider(): array
12341234
'filter_expression_with_in_array_of_values',
12351235
'$[?(@.d in [2, 3])]',
12361236
'[{"d":1},{"d":2},{"d":1},{"d":3},{"d":4}]',
1237-
''
1237+
'[{"d":2},{"d":3}]'
12381238
],
12391239
[ // data set #181 - unknown consensus
12401240
'filter_expression_with_in_current_object',

0 commit comments

Comments
 (0)