fix(anatomy): R5.3 non-object children refused at add, reads confined to the seed, array length in the shape check, only run-created folders, seed guard tested in place
This commit is contained in:
1 parent
42bbc48fcc
commit
86273b6206
6 files changed
+149
-21
No files matched your search
@@ -238,6 +238,31 @@ fn add_destination(doc: &mut Value, op: &AddOp) -> Result<Destination, PipelineE
|
||||
})
|
||||
}
|
||||
|
||||
/// Every entry of a `children` or `categories` list of an added value must be an object. The
|
||||
/// TypeScript met a null or a primitive there inconsistently (a TypeError when it walked it,
|
||||
/// silently skipped when a rename walked past it, refused by the gate when it stayed); the
|
||||
/// port refuses it at the add (RUST.md §11.12). Walked with an explicit stack.
|
||||
fn assert_object_children(value: &Value) -> Result<(), PipelineError> {
|
||||
let mut pending = vec![value];
|
||||
while let Some(item) = pending.pop() {
|
||||
let Some(map) = item.as_object() else {
|
||||
continue;
|
||||
};
|
||||
for key in ["children", "categories"] {
|
||||
let Some(list) = map.get(key).and_then(Value::as_array) else {
|
||||
continue;
|
||||
};
|
||||
if list.iter().any(|entry| !entry.is_object()) {
|
||||
return Err(fail(format!(
|
||||
"the added item holds a \"{key}\" entry that is not an object"
|
||||
)));
|
||||
}
|
||||
pending.extend(list);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_add(
|
||||
doc: &mut Value,
|
||||
recorder: &mut Recorder<'_>,
|
||||
@@ -246,6 +271,7 @@ fn apply_add(
|
||||
let Some(value) = op.value.as_object() else {
|
||||
return Err(fail("add needs an object value"));
|
||||
};
|
||||
assert_object_children(&op.value)?;
|
||||
let dest = add_destination(doc, op)?;
|
||||
let Some(id) = value.get(dest.key).and_then(Value::as_str) else {
|
||||
return Err(fail(format!(
|
||||
|
||||
@@ -44,7 +44,12 @@ fn first_mismatch(written: &Value, typed: &Value, path: &str) -> Option<String>
|
||||
None => Some(format!("unexpected key at {here}")),
|
||||
}
|
||||
}),
|
||||
(Value::Array(w), Value::Array(t)) if w.len() == t.len() => w
|
||||
(Value::Array(w), Value::Array(t)) if w.len() != t.len() => Some(format!(
|
||||
"expected {} items at {path}, received {}",
|
||||
t.len(),
|
||||
w.len()
|
||||
)),
|
||||
(Value::Array(w), Value::Array(t)) => w
|
||||
.iter()
|
||||
.zip(t)
|
||||
.enumerate()
|
||||
|
||||
Reference in new issue
Block a user