[bug] Stdlib RTF fallback drops hex-escaped text

Author: Stamina9Created Sep 23, 2026Updated Sep 23, 2026
Labelsbug

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\'e9 becomes caf instead of café;
  • 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 --check show the relevant extractor installed? no (striprtf absent; dependency-free fallback is the path under test)

Repro

Call strip_rtf_fallback() with these minimal payloads:

rtf
{\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.36s

Environment

  • OS: Windows 11 with WSL
  • Python version: 3.14.4
  • book-to-skill version / commit: master at 80ae087

Source: virgiliojr94/book-to-skill