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
23 changes: 17 additions & 6 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,15 @@ pub fn command_json_arr_append<M: Manager>(

// We require at least one JSON item to append
args.peek().ok_or(RedisError::WrongArity)?;
let args = args
.map(|json| manager.from_str(&json.to_string_lossy(), Format::JSON))
.collect::<Result<_, _>>()?;

let args = args.try_fold::<_, _, Result<_, RedisError>>(
Vec::with_capacity(args.len()),
|mut acc, arg| {
let json = arg.try_as_str()?;
acc.push(manager.from_str(json, Format::JSON)?);
Ok(acc)
},
)?;
Comment thread
gkorland marked this conversation as resolved.
Resolved

let mut redis_key = manager.open_key_write(ctx, key)?;
let root = redis_key
Expand Down Expand Up @@ -930,9 +936,14 @@ pub fn command_json_arr_insert<M: Manager>(

// We require at least one JSON item to append
args.peek().ok_or(RedisError::WrongArity)?;
let args = args
.map(|json| manager.from_str(&json.to_string_lossy(), Format::JSON))
.collect::<Result<_, _>>()?;
let args = args.try_fold::<_, _, Result<_, RedisError>>(
Vec::with_capacity(args.len()),
|mut acc, arg| {
let json = arg.try_as_str()?;
acc.push(manager.from_str(json, Format::JSON)?);
Ok(acc)
},
)?;

let mut redis_key = manager.open_key_write(ctx, key)?;

Expand Down
7 changes: 7 additions & 0 deletions tests/pytest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,13 @@ def testArrPopErrors(env):
r.assertOk(r.execute_command('JSON.SET', 'test','.', '1'))
r.expect('JSON.ARRPOP', 'test').error().contains("not an array")

def testArrWrongChars(env):
r = env

r.assertOk(r.execute_command('JSON.SET', 'test','.', '{"arr":[1,2]}'))
r.expect('JSON.ARRINSERT', 'test', '.arr', 0, b'\x80abc').error().contains("Couldn't parse as UTF-8 string")
r.expect('JSON.ARRAPPEND', 'test', '.arr', b'\x80abc').error().contains("Couldn't parse as UTF-8 string")

def testArrTrimErrors(env):
r = env

Expand Down