Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Require four hex digits in DXF text \U+XXXX escape

NetterSilver2a4aafe34602
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");