细化组件绑定载荷形状校验

在反序列化前拒绝空值和无效的节点组件外部枚举。
This commit is contained in:
2026-09-11 18:54:21 +08:00
parent 3774d7c1e1
commit 87a7294a04
@@ -170,11 +170,22 @@ fn validate_binding_response_shape(
return Err(format!("组件绑定 changes 不能超过 {max_changes}"));
}
for change in changes {
if !change
.as_object()
.is_some_and(|object| object.contains_key("component"))
{
let Some(object) = change.as_object() else {
return Err("组件绑定 change 缺少 component 字段".to_string());
};
let Some(component) = object.get("component") else {
return Err("组件绑定 change 缺少 component 字段".to_string());
};
let valid_component = component == "PureNode"
|| component
.as_object()
.and_then(|value| value.get("WithComponent"))
.is_some_and(serde_json::Value::is_object);
if !valid_component {
return Err(
"组件绑定 change 的 component 必须是 PureNode 或 WithComponent 对象"
.to_string(),
);
}
}
Ok(())