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
16 changes: 12 additions & 4 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,18 @@ impl<'a, V: SelectValue> KeyValue<'a, V> {
.collect())
}
} else if let StaticPathElement::ArrayIndex(_) = last {
// if we reach here with array path we must be out of range
// otherwise the path would be valid to be set and we would not
// have reached here!!
Err("ERR array index out of range".into())
// if we reach here with array path we are either out of range
// or no-oping an NX where the value is already present
let mut selector = Selector::default();
let res = selector
.str_path(path)?
.value(self.val)
.select_with_paths(|_| true)?;
if !res.is_empty() {
Ok(Vec::new())
} else {
Err("ERR array index out of range".into())
}
} else {
Err("ERR path not an object or array".into())
}
Expand Down
7 changes: 7 additions & 0 deletions tests/pytest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,13 @@ def testMultiPathResults(env):
# make sure legacy json path returns single result
env.expect("JSON.GET", "k", '.*[0,2]').equal('1')

def testIssue_597(env):
env.expect("JSON.SET", "test", ".", "[0]").ok()
env.assertEqual(env.execute_command("JSON.SET", "test", ".[0]", "[0]", "NX"), None)
env.expect("JSON.SET", "test", ".[1]", "[0]", "NX").raiseError()
# make sure value was not changed
env.expect("JSON.GET", "test", ".").equal('[0]')

# class CacheTestCase(BaseReJSONTest):
# @property
# def module_args(env):
Expand Down