mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Reject signed hex digits in XML-ID _xHH_ escapes
Found while testing crates/doc/src/xml_id.rs:80 (escaped) 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
c4fba30b9c
commit
add5e1e7dd
@@ -73,7 +73,7 @@ fn escaped(s: &str) -> Option<(char, usize)> {
|
|||||||
let body = s.strip_prefix("_x")?;
|
let body = s.strip_prefix("_x")?;
|
||||||
let end = body.find('_')?;
|
let end = body.find('_')?;
|
||||||
let hex = body.get(..end)?;
|
let hex = body.get(..end)?;
|
||||||
if hex.is_empty() || hex.len() > 6 {
|
if hex.is_empty() || hex.len() > 6 || !hex.bytes().all(|b| b.is_ascii_hexdigit()) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let c = char::from_u32(u32::from_str_radix(hex, 16).ok()?)?;
|
let c = char::from_u32(u32::from_str_radix(hex, 16).ok()?)?;
|
||||||
@@ -113,6 +113,12 @@ mod tests {
|
|||||||
assert!(!is_valid("My Rect") && !is_valid("1abc") && !is_valid(""));
|
assert!(!is_valid("My Rect") && !is_valid("1abc") && !is_valid(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sign_is_not_a_hex_digit_in_escapes() {
|
||||||
|
assert_eq!(to_object_name("a_x+41_b"), "a x+41 b");
|
||||||
|
assert_eq!(to_object_name("a_x-41_b"), "a x-41 b");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_names_that_cannot_start_an_xml_name() {
|
fn round_trip_names_that_cannot_start_an_xml_name() {
|
||||||
for name in ["-abc", ".5 mm", "²x", "Ⅷ", "", "1abc", "Layer 1", " lead", "_a", ":a", "#"] {
|
for name in ["-abc", ".5 mm", "²x", "Ⅷ", "", "1abc", "Layer 1", " lead", "_a", ":a", "#"] {
|
||||||
|
|||||||
Reference in New Issue
Block a user