mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Merge pull request #3986 from Silvertree2010/fix/h1951-dxf-text-u-xxxx-escape-accepts-a
Require four hex digits in DXF text \U+XXXX escape
This commit is contained in:
@@ -71,6 +71,7 @@ fn escapes(s: &str) -> String {
|
||||
let after = rest.get(c.len_utf8()..).unwrap_or("");
|
||||
if c == '\\'
|
||||
&& let Some(hex) = after.strip_prefix("U+").or_else(|| after.strip_prefix("u+")).and_then(|h| h.get(..4))
|
||||
&& hex.bytes().all(|b| b.is_ascii_hexdigit())
|
||||
&& let Some(ch) = u32::from_str_radix(hex, 16).ok().and_then(char::from_u32)
|
||||
{
|
||||
out.push(ch);
|
||||
@@ -135,6 +136,14 @@ fn percent_codes(s: &str) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn unicode_escape_requires_four_hex_digits() {
|
||||
assert_eq!(plain("\\U++041"), "\\U++041");
|
||||
assert_eq!(plain("\\U+00G1"), "\\U+00G1");
|
||||
assert_eq!(plain("\\U+ 041"), "\\U+ 041");
|
||||
assert_eq!(plain("\\U+00C9"), "É");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn control_codes_and_escapes() {
|
||||
assert_eq!(plain("45%%d %%p0.1 %%c20 100%%% %%uunder%%u"), "45° ±0.1 ⌀20 100% under");
|
||||
|
||||
Reference in New Issue
Block a user