mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 20:27:05 -06:00
Merge pull request #4449 from Silvertree2010/fix/h3554-eps-import-glyph-char-accepts-a
Reject non-hex characters in EPS uni/u glyph names
This commit is contained in:
@@ -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