From 4d47c350c1d29ebecf2e7db05c65302dd1f4e2b1 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:30:36 +0100 Subject: [PATCH] Neutralise CR and form feed in CSS variable export strings Found while testing crates/engine/src/cmd/variables_io.rs:~92 (css_safe, used by css for String values and mode names) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/cmd/variables_io.rs | 2 +- crates/engine/src/variables_io_tests.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/variables_io.rs b/crates/engine/src/cmd/variables_io.rs index b9e73f13..f829785b 100644 --- a/crates/engine/src/cmd/variables_io.rs +++ b/crates/engine/src/cmd/variables_io.rs @@ -62,7 +62,7 @@ fn export(s: &mut Session, p: &Value) -> Result { /// `text` as a CSS comment or quoted string body. fn css_safe(text: &str) -> String { - text.replace("*/", "* /").replace(['"', '\\', '\n'], " ") + text.replace("*/", "* /").replace(['"', '\\', '\n', '\r', '\u{c}'], " ") } /// Each collection's variables as custom properties (named as generated code names them): the diff --git a/crates/engine/src/variables_io_tests.rs b/crates/engine/src/variables_io_tests.rs index e8a0239e..55a2336b 100644 --- a/crates/engine/src/variables_io_tests.rs +++ b/crates/engine/src/variables_io_tests.rs @@ -513,3 +513,15 @@ fn review_a_long_alias_chain_keeps_its_role_to_the_end() { let css = ex(&mut s, "variable.export", json!({"format": "css"}))["text"].as_str().unwrap_or_default().to_string(); assert!(css.contains("--o0: 0.5;"), "{css}"); } + +#[test] +fn css_export_neutralises_every_css_newline_in_strings() { + let mut s = Session::new(); + ex(&mut s, "variable.createCollection", json!({"name": "Brand"})); + ex(&mut s, "variable.create", json!({"collection": "Brand", "name": "t", "type": "string", "value": "a\rb\u{c}c"})); + for format in ["css", "tailwind"] { + let css = ex(&mut s, "variable.export", json!({"format": format}))["text"].as_str().unwrap_or_default().to_string(); + assert!(!css.contains('\r') && !css.contains('\u{c}'), "{css:?}"); + assert!(css.contains("\"a b c\""), "{css:?}"); + } +}