From 9c985e6a6ae21d2749b646f5b6c8e9ad60c5b671 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 25 Oct 2026 06:35:40 +0100 Subject: [PATCH] Ignore signed \'hh hex escapes in RTF outline import Found while testing crates/format/src/rtf.rs:226 (rtf_to_outline) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/format/src/rtf.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/format/src/rtf.rs b/crates/format/src/rtf.rs index 5c7cf106..0ab0d6c4 100644 --- a/crates/format/src/rtf.rs +++ b/crates/format/src/rtf.rs @@ -223,7 +223,7 @@ pub fn rtf_to_outline(rtf: &str) -> String { _ => {} } } else if n == b'\'' { - let hex = rtf.get(i + 1..i + 3).and_then(|h| u8::from_str_radix(h, 16).ok()); + let hex = rtf.get(i + 1..i + 3).filter(|h| h.bytes().all(|b| b.is_ascii_hexdigit())).and_then(|h| u8::from_str_radix(h, 16).ok()); i = advance(rtf, i, 3); if !st.skip && let Some(h) = hex @@ -318,6 +318,12 @@ mod tests { #![allow(clippy::unwrap_used)] use super::*; + /// A sign in a `\'hh` escape is not a hex digit and must be ignored. + #[test] + fn hex_escape_rejects_sign() { + assert_eq!(rtf_to_outline(r"{\rtf1 a\'+5b\par}"), "ab\n"); + } + /// Non-ASCII text after a `\\uN` or `\\'hh` escape used to split a character and panic. #[test] fn non_ascii_text_after_escapes_does_not_panic() {