Merge pull request #1351

This commit is contained in:
Brandon Thomas
2026-10-25 13:42:04 -04:00
+7 -1
View File
@@ -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() {