From 87a7294a04cafbfaa24f27de1fe4e52a60db82cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 11 Sep 2026 18:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E5=8C=96=E7=BB=84=E4=BB=B6=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E8=BD=BD=E8=8D=B7=E5=BD=A2=E7=8A=B6=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在反序列化前拒绝空值和无效的节点组件外部枚举。 --- .../src/ui_editor/commands/binding.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs index 17979cbca..d6eb3ba8d 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs @@ -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(())