forked from extern/nushell
Merge pull request #317 from jonathandturner/fix_Add
Fix adding at shallow depth
This commit is contained in:
commit
db125b4318
@ -354,7 +354,16 @@ impl Value {
|
|||||||
|
|
||||||
if let Value::Object(ref mut o) = new_obj {
|
if let Value::Object(ref mut o) = new_obj {
|
||||||
let mut current = o;
|
let mut current = o;
|
||||||
for idx in 0..split_path.len() - 1 {
|
|
||||||
|
if split_path.len() == 1 {
|
||||||
|
// Special case for inserting at the top level
|
||||||
|
current
|
||||||
|
.entries
|
||||||
|
.insert(path.to_string(), Tagged::from_item(new_value, tag));
|
||||||
|
return Some(Tagged::from_item(new_obj, tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx in 0..split_path.len() {
|
||||||
match current.entries.get_mut(split_path[idx]) {
|
match current.entries.get_mut(split_path[idx]) {
|
||||||
Some(next) => {
|
Some(next) => {
|
||||||
if idx == (split_path.len() - 2) {
|
if idx == (split_path.len() - 2) {
|
||||||
|
@ -23,9 +23,10 @@ impl Add {
|
|||||||
Some(f) => match obj.insert_data_at_path(value_tag, &f, v) {
|
Some(f) => match obj.insert_data_at_path(value_tag, &f, v) {
|
||||||
Some(v) => return Ok(v),
|
Some(v) => return Ok(v),
|
||||||
None => {
|
None => {
|
||||||
return Err(ShellError::string(
|
return Err(ShellError::string(format!(
|
||||||
"add could not find place to insert field",
|
"add could not find place to insert field {:?} {}",
|
||||||
))
|
obj, f
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => Err(ShellError::string(
|
None => Err(ShellError::string(
|
||||||
|
Loading…
Reference in New Issue
Block a user