mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 20:27:05 -06:00
Reject non-hex characters in EPS uni/u glyph names
Found while testing crates/eps/src/import/text.rs:501-502 (glyph_char) 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
de6b14b541
commit
aca98ffe79
@@ -499,6 +499,7 @@ fn glyph_char(name: &str) -> char {
|
||||
return c;
|
||||
}
|
||||
if let Some(hex) = name.strip_prefix("uni").or_else(|| name.strip_prefix('u'))
|
||||
&& hex.chars().all(|c| c.is_ascii_hexdigit())
|
||||
&& let Some(c) = u32::from_str_radix(hex, 16).ok().and_then(char::from_u32)
|
||||
{
|
||||
return c;
|
||||
@@ -508,3 +509,16 @@ fn glyph_char(name: &str) -> char {
|
||||
_ => '\u{2022}',
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::glyph_char;
|
||||
|
||||
#[test]
|
||||
fn glyph_char_rejects_plus_in_hex() {
|
||||
assert_eq!(glyph_char("uni20AC"), '€');
|
||||
assert_eq!(glyph_char("u1F600"), '\u{1F600}');
|
||||
assert_eq!(glyph_char("uni+041"), '\u{2022}');
|
||||
assert_eq!(glyph_char("u+41"), '\u{2022}');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user