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:
BFlat
2026-10-29 09:56:01 +07:00
committed by GitHub
+14
View File
@@ -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}');
}
}