From 3dfd7393c27663967a2d049ddbce7a4c98215c15 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 11:14:37 -0800 Subject: [PATCH] Paint: an opacity call refuses a bad target with an id or selected characters The opacity path of paint.setFill and paint.setStroke (apply_paint_opacity) never checked `target` or `aligned`. With `id` or `ids` naming an object, item_target reads no `target`, so a call such as {"opacity": 40, "target": "content", "id": ...} painted the object instead of failing. The test added in 6898eed99 covers that case, and the opacity path from 4f065ccbb (Show Opacity in the Color Wheel panel) merged beside it without the check, so main's gate failed on tests::paintopacity::a_bad_target_is_refused_with_an_id_or_selected_characters. The opacity path now runs the same two checks as the color path (tool_color_params): appearance::aligned and appearance::targets_contents. Valid values are read where they were before. --- crates/engine/src/cmd/paint.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 0606ba0130..1ac467789c 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -945,6 +945,10 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option, opacity let cmd = if fill { "paint.setFill" } else { "paint.setStroke" }; let for_tool = tool_color_params(s, p, cmd, !fill)?; let p = for_tool.as_ref().unwrap_or(p); + // A bad `target` or `aligned` is refused for every kind of target: `item_target` reads no + // `target` once `id` or `ids` names an object, and selected characters read neither. + super::appearance::aligned(p, cmd)?; + super::appearance::targets_contents(p)?; let focus = switch_or(p, "focus", true, cmd)?; // An opacity alone places no gradient, so `span` may only be "object" with it. let span = spans_targets(p, paint.as_ref().unwrap_or(&Paint::None)).map_err(|e| bad(cmd, e))?;