From cfd31b50104e2369787f2729d9c571b9117bba47 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 3 Nov 2026 23:29:31 +0700 Subject: [PATCH] CSS export: line breaks and angle brackets in names can't end a CSS string Squashed from #5408 onto main. --- crates/svg/src/css.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/svg/src/css.rs b/crates/svg/src/css.rs index 05ab3ce55..1b19da801 100644 --- a/crates/svg/src/css.rs +++ b/crates/svg/src/css.rs @@ -26,7 +26,28 @@ pub(crate) fn declarations<'a>(props: impl IntoIterator String { - format!("\"{}\"", s.replace('\\', "\\\\").replace('"', "\\\"")) + quoted(s, '"') +} + +/// `s` as a CSS string in `quote`s. A backslash and the quote are escaped, and so are line breaks +/// and other control characters (a newline would end the string and let the rest be rules) and +/// `<` and `>` (which could end a `"), r#""w\d \"\3c /style\3e ""#); + assert_eq!(css_string("wght"), "\"wght\""); + } }