[bug] Stdlib RTF fallback drops hex-escaped text
What happened
When the optional striprtf package is unavailable, the dependency-free RTF fallback replaces every standalone hex-escaped byte (\'hh) with a space. These escapes are how many legacy RTF files encode visible non-ASCII text, so content is silently lost:
caf\'e9becomescafinstead ofcafé;- cp1251-escaped Cyrillic becomes whitespace; and
- multibyte code pages such as cp932 lose the encoded characters entirely.
The same syntax can also appear immediately after an RTF \\\uN Unicode escape as a one-character compatibility fallback. That byte should still be consumed rather than emitted; the bug concerns the standalone escapes that remain afterward.
What you expected
After consuming \\\uN compatibility fallbacks, the stdlib parser should decode remaining hex byte runs using the document's declared \ansicpgN code page, defaulting to Windows-1252 when none is declared.
Source document
- Format: RTF (synthetic strings; no copyrighted text)
- Pages / size: one line / under 1 KB
- Language: French sample, Russian, and Japanese
- Does
python3 scripts/extract.py --checkshow the relevant extractor installed? no (striprtfabsent; dependency-free fallback is the path under test)
Repro
Call strip_rtf_fallback() with these minimal payloads:
{\rtf1\ansi caf\'e9 and \'93quoted\'94.}
{\rtf1\ansi\ansicpg1251 \'cf\'f0\'e8\'e2\'e5\'f2}Current output:
'caf and quoted .'
' 'Expected output:
'café and “quoted”.'
'Привет'Three focused regressions also cover cp932 multibyte decoding. Against current master (80ae087):
3 failed in 1.36sEnvironment
- OS: Windows 11 with WSL
- Python version: 3.14.4
- book-to-skill version / commit:
masterat80ae087
Source: virgiliojr94/book-to-skill