From e371bc34e389cafe5c4debc71c246909e4ef0db4 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 18 Oct 2026 22:57:53 +0200 Subject: [PATCH] Refuse strict .atn export of Apply Image with a blending mask Fixes #7247 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/atn_cmds.rs | 9 +++++++++ crates/engine/src/atn_cmds/tests.rs | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs index 9e8eb6cb7c..a897876b40 100644 --- a/crates/engine/src/atn_cmds.rs +++ b/crates/engine/src/atn_cmds.rs @@ -1736,6 +1736,15 @@ fn apply_image_from(d: &Descriptor) -> Mapped { } fn apply_image_to(_: &str, p: &Value) -> Option { + // The optional blending mask has no descriptor mapping: refuse it rather than drop it, + // which would widen the edit to the whole layer. + let mask_channel = match p.get("mask") { + Some(m) => m.get("channel"), + None => p.get("maskChannel"), + }; + if mask_channel.is_some_and(|c| !(c.is_null() || c == "none" || c == "")) { + return None; + } let source = p.get("source").cloned().unwrap_or(json!({})); let channel = jstr(&source, "channel").unwrap_or("composite"); let chan = lookup_back(SOURCE_CHANNELS, channel).or_else(|| lookup_back(CHANNELS, channel))?; diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs index 26865d4060..1d32b4eecd 100644 --- a/crates/engine/src/atn_cmds/tests.rs +++ b/crates/engine/src/atn_cmds/tests.rs @@ -1387,3 +1387,23 @@ fn function_keys_keep_shift_and_command() { } assert_eq!(super::function_key_name(7, false, false), "F7"); } + +/// Apply Image's optional blending mask has no `.atn` mapping: a strict export must refuse the +/// step rather than drop the mask and widen the edit to the whole layer. +#[test] +fn apply_image_with_blending_mask_is_not_exported_without_its_mask() { + let source = json!({"layer": "Pixels", "channel": "green", "invert": true}); + for params in [json!({"source": source, "blending": "normal", "mask": {"channel": 0}}), json!({"source": source, "blending": "normal", "maskChannel": 0})] { + let masked = Action { name: "Masked".into(), steps: vec![("image.applyImage".into(), params.clone())], ..Default::default() }; + assert!(export("Audit5", &[&masked], &[], false).is_err(), "{params}"); + let (_, skipped) = export("Audit5", &[&masked], &[], true).unwrap(); + assert_eq!(skipped, vec![Skipped { action: "Masked".into(), step: 0, id: "image.applyImage".into() }]); + } + for params in [json!({"source": source, "blending": "normal"}), json!({"source": source, "blending": "normal", "mask": {"channel": "none"}})] { + let plain = Action { name: "Plain".into(), steps: vec![("image.applyImage".into(), params.clone())], ..Default::default() }; + let (bytes, skipped) = export("Audit5", &[&plain], &[], false).unwrap(); + assert!(skipped.is_empty()); + let imported = import(&bytes).unwrap(); + assert_eq!(imported.actions[0].steps, vec![("image.applyImage".to_string(), json!({"source": source, "blending": "normal"}))]); + } +}