mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Merge pull request #3860 from Silvertree2010/fix/h1829-xml-id-unescape-accepts-a-sign-i
Reject signed hex digits in XML-ID _xHH_ escapes
This commit is contained in:
@@ -73,7 +73,7 @@ fn escaped(s: &str) -> Option<(char, usize)> {
|
||||
let body = s.strip_prefix("_x")?;
|
||||
let end = body.find('_')?;
|
||||
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;
|
||||
}
|
||||
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(""));
|
||||
}
|
||||
|
||||
#[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]
|
||||
fn round_trip_names_that_cannot_start_an_xml_name() {
|
||||
for name in ["-abc", ".5 mm", "²x", "Ⅷ", "", "1abc", "Layer 1", " lead", "_a", ":a", "#"] {
|
||||
|
||||
Reference in New Issue
Block a user