mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 20:27:05 -06:00
Reject non-hex digits in RTF \'XX escapes
Found while testing crates/engine/src/cmd/place/rtf.rs:111 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
26f9b7f80c
commit
66498b9740
@@ -108,7 +108,12 @@ pub(super) fn import(bytes: &[u8], cmd: &str) -> Result<Story> {
|
||||
match next {
|
||||
b'*' => starred = true,
|
||||
b'\'' => {
|
||||
if let Some(v) = bytes.get(i..i + 2).and_then(|h| std::str::from_utf8(h).ok()).and_then(|h| u8::from_str_radix(h, 16).ok()) {
|
||||
if let Some(v) = bytes
|
||||
.get(i..i + 2)
|
||||
.filter(|h| h.iter().all(u8::is_ascii_hexdigit))
|
||||
.and_then(|h| std::str::from_utf8(h).ok())
|
||||
.and_then(|h| u8::from_str_radix(h, 16).ok())
|
||||
{
|
||||
i += 2;
|
||||
r.byte(v);
|
||||
}
|
||||
@@ -650,6 +655,13 @@ mod tests {
|
||||
assert_eq!(text_of(&mac), "é•", "Mac Roman");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_escapes_need_two_hex_digits() {
|
||||
assert_eq!(text_of(&read(r"{\rtf1\ansi A\'+1B}")), "A+1B");
|
||||
assert_eq!(text_of(&read(r"{\rtf1\ansi A\'-1B}")), "A-1B");
|
||||
assert_eq!(text_of(&read(r"{\rtf1\ansi A\'g0B}")), "Ag0B");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upr_groups_read_their_unicode_text() {
|
||||
let s = read(concat!(r"{\rtf1 a{\upr{\f0 b?}{\*\ud{\f0 c\u", "945", r"?}}}d}"));
|
||||
|
||||
Reference in New Issue
Block a user