From d4622f78f23dedc8ab0de8d061fdc90d5011b080 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 1 Nov 2026 00:18:06 -0600 Subject: [PATCH] Copy CSS: test a comment closer in a name and a layer with a drop shadow (FredApps review) A layer named `a */ b` writes no `*/` outside its quoted image name and a sanitised class; a layer with a drop shadow writes the same rule as without it, with no shadow and no panic. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layer_css_cmds/tests.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/crates/engine/src/cmd/layer_css_cmds/tests.rs b/crates/engine/src/cmd/layer_css_cmds/tests.rs index 06a46b1224..0d4ecc3b89 100644 --- a/crates/engine/src/cmd/layer_css_cmds/tests.rs +++ b/crates/engine/src/cmd/layer_css_cmds/tests.rs @@ -170,3 +170,45 @@ fn a_rounded_rectangle_writes_its_border_radius() { let css = s.execute(ID, json!({"layer": id})).unwrap()["css"].as_str().unwrap().to_string(); assert!(!css.contains("border-radius") && css.contains(" background-color: rgb(255, 0, 0);\n"), "{css}"); } + +/// `css` without its double-quoted strings (escapes inside them skipped). +fn outside_strings(css: &str) -> String { + let (mut out, mut quoted, mut escaped) = (String::new(), false, false); + for c in css.chars() { + match (quoted, escaped, c) { + (true, true, _) => escaped = false, + (true, false, '\\') => escaped = true, + (_, false, '"') => quoted = !quoted, + (false, _, _) => out.push(c), + _ => {} + } + } + out +} + +/// A name with a comment closer can't end a comment or break the rule: outside the quoted image +/// name there is no `*/`, and the class is sanitised. +#[test] +fn a_comment_closer_in_a_name_stays_inside_the_string() { + let css = session("a */ b").execute(ID, json!({})).unwrap()["css"].as_str().unwrap().to_string(); + assert!(!outside_strings(&css).contains("*/"), "{css}"); + assert!(css.starts_with(".a____b {\n background-image: url(\"a */ b.png\");\n"), "{css}"); +} + +/// Layer effects aren't written: a layer with a drop shadow gives the same rule as without it, +/// placed and sized by its pixels, not the shadow. +#[test] +fn a_layer_with_a_drop_shadow_writes_its_rule_without_the_effect() { + let mut s = session("Box"); + let plain = s.execute(ID, json!({})).unwrap()["css"].as_str().unwrap().to_string(); + s.edit("fx", |doc, active| { + let l = doc.layer_mut(active.unwrap()).unwrap(); + l.effects.enabled = true; + l.effects.items.push(photocraft_doc::effects::Effect::default_drop_shadow()); + Ok(()) + }) + .unwrap(); + let css = s.execute(ID, json!({})).unwrap()["css"].as_str().unwrap().to_string(); + assert_eq!(css, plain); + assert!(!css.contains("shadow"), "{css}"); +}