From 64f1e0b61d55092f2d30270113601178108c892b Mon Sep 17 00:00:00 2001 From: seotarek Date: Sun, 18 Oct 2026 05:44:49 +0300 Subject: [PATCH 1/2] fix(atn): reject non-replace select.rect modes in .atn export (#7194) --- crates/engine/src/atn_cmds.rs | 4 ++++ crates/engine/src/atn_cmds/tests.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs index 9e8eb6cb7c..3441f8d959 100644 --- a/crates/engine/src/atn_cmds.rs +++ b/crates/engine/src/atn_cmds.rs @@ -1354,6 +1354,10 @@ fn set_to(id: &str, p: &Value) -> Option { desc("null").with("null", quick_mask_ref()) } "select.rect" => { + match jstr(p, "mode") { + None | Some("replace") => {} + Some(_) => return None, + } let (x, y, w, h) = (jnum(p, "x")?, jnum(p, "y")?, jnum(p, "width")?, jnum(p, "height")?); let cls = if jbool(p, "ellipse") == Some(true) { "Elps" } else { "Rctn" }; sel(D::Descriptor(desc(cls).with("Top ", px(y)).with("Left", px(x)).with("Btom", px(y + h)).with("Rght", px(x + w)))) diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs index 26865d4060..0a988919f1 100644 --- a/crates/engine/src/atn_cmds/tests.rs +++ b/crates/engine/src/atn_cmds/tests.rs @@ -1387,3 +1387,29 @@ fn function_keys_keep_shift_and_command() { } assert_eq!(super::function_key_name(7, false, false), "F7"); } + +#[test] +fn select_rect_mode_strict_export_rejects_unrepresentable_modes() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); + + // Default or "replace" mode succeeds + s.actions.list.push(Action::new("ReplaceAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "replace"}))])); + let saved = s.execute("actions.save", json!({"action": "ReplaceAct"})).unwrap(); + assert_eq!(saved["steps"], 1); + + // "add" mode cannot be silently converted to replace (set) in strict export + s.actions.list.push(Action::new("AddAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "add"}))])); + let err = s.execute("actions.save", json!({"action": "AddAct"})); + assert!(err.is_err(), "strict export must reject select.rect with add mode rather than converting to replace"); + + // "subtract" mode cannot be silently converted to replace either + s.actions.list.push(Action::new("SubtractAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "subtract"}))])); + let err_subtract = s.execute("actions.save", json!({"action": "SubtractAct"})); + assert!(err_subtract.is_err(), "strict export must reject select.rect with subtract mode rather than converting to replace"); + + // With skipUnsupported: true, unrepresentable modes are reported in skipped + let skipped = s.execute("actions.save", json!({"action": "AddAct", "skipUnsupported": true})).unwrap(); + assert_eq!(skipped["steps"], 0); + assert_eq!(skipped["skipped"][0]["id"], "select.rect"); +} From 7145df8ded385ce253ca3f0c90866712f2bf2377 Mon Sep 17 00:00:00 2001 From: seotarek Date: Mon, 19 Oct 2026 23:45:51 +0300 Subject: [PATCH 2/2] test(atn): assert actions state unchanged after rejected select.rect export --- crates/engine/src/atn_cmds/tests.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs index 0a988919f1..2106123a70 100644 --- a/crates/engine/src/atn_cmds/tests.rs +++ b/crates/engine/src/atn_cmds/tests.rs @@ -1400,13 +1400,17 @@ fn select_rect_mode_strict_export_rejects_unrepresentable_modes() { // "add" mode cannot be silently converted to replace (set) in strict export s.actions.list.push(Action::new("AddAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "add"}))])); + let before_actions = s.actions.list.clone(); let err = s.execute("actions.save", json!({"action": "AddAct"})); assert!(err.is_err(), "strict export must reject select.rect with add mode rather than converting to replace"); + assert_eq!(s.actions.list, before_actions, "actions list must remain unchanged after rejected save"); // "subtract" mode cannot be silently converted to replace either s.actions.list.push(Action::new("SubtractAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "subtract"}))])); + let before_actions_sub = s.actions.list.clone(); let err_subtract = s.execute("actions.save", json!({"action": "SubtractAct"})); assert!(err_subtract.is_err(), "strict export must reject select.rect with subtract mode rather than converting to replace"); + assert_eq!(s.actions.list, before_actions_sub, "actions list must remain unchanged after rejected save"); // With skipUnsupported: true, unrepresentable modes are reported in skipped let skipped = s.execute("actions.save", json!({"action": "AddAct", "skipUnsupported": true})).unwrap();