mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
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 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
bc041e15ef
commit
2a4aafe346
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user