Ensure non-defined array fields are removed from records
Related to #1341
This commit is contained in:
parent
48a8d7b6eb
commit
8fe5757688
1 changed files with 18 additions and 14 deletions
|
@ -30,13 +30,11 @@ impl Value {
|
||||||
// Current path part is an array
|
// Current path part is an array
|
||||||
Value::Array(v) => match arrays {
|
Value::Array(v) => match arrays {
|
||||||
// Let's log all individual array items
|
// Let's log all individual array items
|
||||||
true => v
|
true => std::iter::once(prev.clone())
|
||||||
.iter()
|
.chain(v.iter().enumerate().rev().flat_map(|(i, v)| {
|
||||||
.enumerate()
|
|
||||||
.flat_map(|(i, v)| {
|
|
||||||
let p = Part::from(i.to_owned());
|
let p = Part::from(i.to_owned());
|
||||||
v._every(steps, arrays, prev.clone().push(p))
|
v._every(steps, arrays, prev.clone().push(p))
|
||||||
})
|
}))
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
// Let's not log individual array items
|
// Let's not log individual array items
|
||||||
false => vec![prev],
|
false => vec![prev],
|
||||||
|
@ -65,12 +63,15 @@ mod tests {
|
||||||
fn every_including_array_indexes() {
|
fn every_including_array_indexes() {
|
||||||
let val = Value::parse("{ test: { something: [{ age: 34, tags: ['code', 'databases'] }, { age: 36, tags: ['design', 'operations'] }] } }");
|
let val = Value::parse("{ test: { something: [{ age: 34, tags: ['code', 'databases'] }, { age: 36, tags: ['design', 'operations'] }] } }");
|
||||||
let res = vec![
|
let res = vec![
|
||||||
Idiom::parse("test.something[0].age"),
|
Idiom::parse("test.something"),
|
||||||
Idiom::parse("test.something[0].tags[0]"),
|
|
||||||
Idiom::parse("test.something[0].tags[1]"),
|
|
||||||
Idiom::parse("test.something[1].age"),
|
Idiom::parse("test.something[1].age"),
|
||||||
Idiom::parse("test.something[1].tags[0]"),
|
Idiom::parse("test.something[1].tags"),
|
||||||
Idiom::parse("test.something[1].tags[1]"),
|
Idiom::parse("test.something[1].tags[1]"),
|
||||||
|
Idiom::parse("test.something[1].tags[0]"),
|
||||||
|
Idiom::parse("test.something[0].age"),
|
||||||
|
Idiom::parse("test.something[0].tags"),
|
||||||
|
Idiom::parse("test.something[0].tags[1]"),
|
||||||
|
Idiom::parse("test.something[0].tags[0]"),
|
||||||
];
|
];
|
||||||
assert_eq!(res, val.every(false, true));
|
assert_eq!(res, val.every(false, true));
|
||||||
}
|
}
|
||||||
|
@ -87,14 +88,17 @@ mod tests {
|
||||||
let val = Value::parse("{ test: { something: [{ age: 34, tags: ['code', 'databases'] }, { age: 36, tags: ['design', 'operations'] }] } }");
|
let val = Value::parse("{ test: { something: [{ age: 34, tags: ['code', 'databases'] }, { age: 36, tags: ['design', 'operations'] }] } }");
|
||||||
let res = vec![
|
let res = vec![
|
||||||
Idiom::parse("test"),
|
Idiom::parse("test"),
|
||||||
Idiom::parse("test.something[0]"),
|
Idiom::parse("test.something"),
|
||||||
Idiom::parse("test.something[0].age"),
|
|
||||||
Idiom::parse("test.something[0].tags[0]"),
|
|
||||||
Idiom::parse("test.something[0].tags[1]"),
|
|
||||||
Idiom::parse("test.something[1]"),
|
Idiom::parse("test.something[1]"),
|
||||||
Idiom::parse("test.something[1].age"),
|
Idiom::parse("test.something[1].age"),
|
||||||
Idiom::parse("test.something[1].tags[0]"),
|
Idiom::parse("test.something[1].tags"),
|
||||||
Idiom::parse("test.something[1].tags[1]"),
|
Idiom::parse("test.something[1].tags[1]"),
|
||||||
|
Idiom::parse("test.something[1].tags[0]"),
|
||||||
|
Idiom::parse("test.something[0]"),
|
||||||
|
Idiom::parse("test.something[0].age"),
|
||||||
|
Idiom::parse("test.something[0].tags"),
|
||||||
|
Idiom::parse("test.something[0].tags[1]"),
|
||||||
|
Idiom::parse("test.something[0].tags[0]"),
|
||||||
];
|
];
|
||||||
assert_eq!(res, val.every(true, true));
|
assert_eq!(res, val.every(true, true));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue