Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,15 @@ impl<'a> WriteHolder<Value, Value> for KeyHolderWrite<'a> {
if let Some(array) = v.as_array() {
let len = array.len() as i64;
let stop = stop.normalize(len);

let range = if start > len || start > stop as i64 || len == 0 {
let start = if start < 0 || start < len {
start.normalize(len)
} else {
stop + 1 // start >=0 && start >= len
};
let range = if start > stop || len == 0 {
0..0 // Return an empty array
} else {
start.normalize(len)..(stop + 1)
start..(stop + 1)
};

let mut new_value = v.take();
Expand Down
8 changes: 8 additions & 0 deletions tests/pytest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,14 @@ def testArrTrimCommand(env):

r.assertEqual(r.execute_command('JSON.ARRTRIM', 'test', '.arr', -1, 0), 0)

r.assertOk(r.execute_command('JSON.SET', 'test',
'.', '{ "arr": [0, 1, 2, 3, 2, 1, 0] }'))
r.assertEqual(r.execute_command('JSON.ARRTRIM', 'test', '.arr', -1, 0), 0)

r.assertOk(r.execute_command('JSON.SET', 'test',
'.', '{ "arr": [0, 1, 2, 3, 2, 1, 0] }'))
r.assertEqual(r.execute_command('JSON.ARRTRIM', 'test', '.arr', -4, 1), 0)


def testArrPopCommand(env):
"""Test JSON.ARRPOP command"""
Expand Down