Bugfix - Include index part when patching object value (#1994)

This commit is contained in:
hchockarprasad 2023-05-16 01:52:13 +05:30 committed by GitHub
parent c02d176646
commit a8f35611c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 12 deletions

View file

@ -9,20 +9,29 @@ impl Value {
// Get the current path part // Get the current path part
match self { match self {
// Current path part is an object // Current path part is an object
Value::Object(v) => { Value::Object(v) => match p {
if let Part::Field(f) = p { Part::Field(f) => match path.len() {
match path.len() { 1 => {
1 => { v.remove(f.as_str());
v.remove(f.as_str()); }
} _ => {
_ => { if let Some(v) = v.get_mut(f.as_str()) {
if let Some(v) = v.get_mut(f.as_str()) { v.cut(path.next())
v.cut(path.next())
}
} }
} }
} },
} Part::Index(i) => match path.len() {
1 => {
v.remove(&i.to_string());
}
_ => {
if let Some(v) = v.get_mut(&i.to_string()) {
v.cut(path.next())
}
}
},
_ => {}
},
// Current path part is an array // Current path part is an array
Value::Array(v) => match p { Value::Array(v) => match p {
Part::All => match path.len() { Part::All => match path.len() {

View file

@ -36,6 +36,16 @@ impl Value {
_ => Ok(()), _ => Ok(()),
}, },
}, },
Part::Index(i) => match path.len() {
1 => {
v.remove(&i.to_string());
Ok(())
}
_ => match v.get_mut(&i.to_string()) {
Some(v) if v.is_some() => v.del(ctx, opt, txn, path.next()).await,
_ => Ok(()),
},
},
_ => Ok(()), _ => Ok(()),
}, },
// Current path part is an array // Current path part is an array

View file

@ -34,6 +34,10 @@ impl Value {
Some(v) => v.fetch(ctx, opt, txn, path.next()).await, Some(v) => v.fetch(ctx, opt, txn, path.next()).await,
None => Ok(()), None => Ok(()),
}, },
Part::Index(i) => match v.get_mut(&i.to_string()) {
Some(v) => v.fetch(ctx, opt, txn, path.next()).await,
None => Ok(()),
},
Part::All => self.fetch(ctx, opt, txn, path.next()).await, Part::All => self.fetch(ctx, opt, txn, path.next()).await,
_ => Ok(()), _ => Ok(()),
}, },

View file

@ -14,6 +14,10 @@ impl Value {
Some(v) => v.pick(path.next()), Some(v) => v.pick(path.next()),
None => Value::None, None => Value::None,
}, },
Part::Index(i) => match v.get(&i.to_string()) {
Some(v) => v.pick(path.next()),
None => Value::None,
},
Part::All => self.pick(path.next()), Part::All => self.pick(path.next()),
_ => Value::None, _ => Value::None,
}, },

View file

@ -26,6 +26,14 @@ impl Value {
v.insert(f.to_raw(), obj); v.insert(f.to_raw(), obj);
} }
}, },
Part::Index(i) => match v.get_mut(&i.to_string()) {
Some(v) if v.is_some() => v.put(path.next(), val),
_ => {
let mut obj = Value::base();
obj.put(path.next(), val);
v.insert(i.to_string(), obj);
}
},
_ => (), _ => (),
}, },
// Current path part is an array // Current path part is an array

View file

@ -43,6 +43,15 @@ impl Value {
Ok(()) Ok(())
} }
}, },
Part::Index(i) => match v.get_mut(&i.to_string()) {
Some(v) if v.is_some() => v.set(ctx, opt, txn, path.next(), val).await,
_ => {
let mut obj = Value::base();
obj.set(ctx, opt, txn, path.next(), val).await?;
v.insert(i.to_string(), obj);
Ok(())
}
},
_ => Ok(()), _ => Ok(()),
}, },
// Current path part is an array // Current path part is an array

View file

@ -17,6 +17,10 @@ impl Value {
Some(v) => v._walk(path.next(), prev.push(p.clone())), Some(v) => v._walk(path.next(), prev.push(p.clone())),
None => Value::None._walk(path.next(), prev.push(p.clone())), None => Value::None._walk(path.next(), prev.push(p.clone())),
}, },
Part::Index(i) => match v.get(&i.to_string()) {
Some(v) => v._walk(path.next(), prev.push(p.clone())),
None => Value::None._walk(path.next(), prev.push(p.clone())),
},
Part::All => self._walk(path.next(), prev.push(p.clone())), Part::All => self._walk(path.next(), prev.push(p.clone())),
_ => vec![], _ => vec![],
}, },