Skip to content

Commit 36879d5

Browse files
authored
Merge pull request #26 from SG5/negative-short-array
large slice for short array, fix #7
2 parents b8b166e + 22067e0 commit 36879d5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Filters/SliceFilter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function filter($collection): array
3232

3333
if ($start < 0) {
3434
$start = $length + $start;
35+
if ($start < 0) {
36+
$start = 0;
37+
}
3538
}
3639

3740
if ($end === null) {

tests/JSONPathTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public function testFilterSliceNegativeStartIndexes(): void
135135
->find('$[-1:]');
136136

137137
self::assertEquals(['fifth'], $result->getData());
138+
139+
$result = (new JSONPath(['first', 'second', 'third']))
140+
->find('$[-4:]');
141+
142+
self::assertEquals(['first','second','third'], $result->getData());
138143
}
139144

140145
/**

0 commit comments

Comments
 (0)