From 2a4aafe346025dde37e1f061399c16c338885ec4 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:59:09 +0200 Subject: [PATCH] Require four hex digits in DXF text \U+XXXX escape Found while testing crates/cad/src/import/text.rs:73-74 (escapes) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/cad/src/import/text.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/cad/src/import/text.rs b/crates/cad/src/import/text.rs index caf5f9bea..8800aa270 100644 --- a/crates/cad/src/import/text.rs +++ b/crates/cad/src/import/text.rs @@ -71,6 +71,7 @@ fn escapes(s: &str) -> String { let after = rest.get(c.len_utf8()..).unwrap_or(""); if c == '\\' && let Some(hex) = after.strip_prefix("U+").or_else(|| after.strip_prefix("u+")).and_then(|h| h.get(..4)) + && hex.bytes().all(|b| b.is_ascii_hexdigit()) && let Some(ch) = u32::from_str_radix(hex, 16).ok().and_then(char::from_u32) { out.push(ch); @@ -135,6 +136,14 @@ fn percent_codes(s: &str) -> String { mod tests { use super::*; + #[test] + fn unicode_escape_requires_four_hex_digits() { + assert_eq!(plain("\\U++041"), "\\U++041"); + assert_eq!(plain("\\U+00G1"), "\\U+00G1"); + assert_eq!(plain("\\U+ 041"), "\\U+ 041"); + assert_eq!(plain("\\U+00C9"), "É"); + } + #[test] fn control_codes_and_escapes() { assert_eq!(plain("45%%d %%p0.1 %%c20 100%%% %%uunder%%u"), "45° ±0.1 ⌀20 100% under");