Skip to content

fix(rtf): accept UTF-8 BOMs in imported outlines - #2298

Open
MMexicann wants to merge 1 commit into
storytold:mainfrom
MMexicann:patch-29
Open

MMexicann wants to merge 1 commit into
storytold:mainfrom
MMexicann:patch-29

Conversation

@MMexicann

@MMexicann MMexicann commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

DeckCraft can open and insert UTF-8 RTF outlines that start with a byte order mark.

The shared RTF sniffer rejected the leading mark, and the outline parser could treat the mark as part of the first title. Drop one leading BOM at the import boundary before sniffing and paragraph parsing. Both import routes still use the pinned shared lexer.

The regression checks detection and the resulting outline text. The focused Rust harness reproduced both failures and passed 11 tests with the fix, including the pinned lexer tests. It used the current importer and a presentation test double. Full crate checks were left to CI.

Summary by CodeRabbit

  • Bug Fixes
    • RTF documents with an initial UTF-8 BOM are now recognized and parsed correctly, including their outlines.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The RTF handler now checks for RTF content after an optional UTF-8 BOM and removes an initial Unicode BOM before parsing. A test covers BOM-prefixed RTF with leading whitespace.

Changes: RTF BOM handling

Layer / File(s) Summary
BOM detection and parsing
crates/format/src/rtf.rs
sniff_rtf checks input after an optional UTF-8 BOM. paragraphs removes an initial Unicode BOM. A test checks recognition and parsing of BOM-prefixed RTF with leading whitespace.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: dylanmtaylor, harrison-booth

Merge Risk: Minimal · up to 18d75

This change lets DeckCraft open and insert UTF-8 RTF outlines that begin with a byte order mark. The change is narrow and has a regression test, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(rtf): accept UTF-8 BOMs in imported outlines" matches the main change. The raw summary says sniff_rtf now accepts an initial UTF-8 BOM and paragraphs strips a leading Unicode BOM, with …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(rtf): accept UTF-8 BOMs in imported outlines" matches the main change. The raw summary says sniff_rtf now accepts an initial UTF-8 BOM and paragraphs strips a leading Unicode BOM, with a test for BOM-prefixed RTF. The PR objectives say the change lets DeckCraft open and insert UTF-8 RTF outlines that begin with a BOM. The title is specific, concise, and uses a conventional type(scope) prefix.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0ccc68f and 18d7537.

Files selected for processing: 1

  • crates/format/src/rtf.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@autocraft-bot autocraft-bot Bot added the bugfix Fixes something that is broken: wrong result, crash, data loss label Nov 21, 2026
@MMexicann
MMexicann marked this pull request as ready for review November 21, 2026 18:21

@autocraft-bot autocraft-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Claude Opus 5.5). Not a maintainer decision.

No blocking problems found (not certain).

Strips one leading UTF-8 BOM before RTF sniffing and before outline paragraph parsing, and adds a regression test covering detection and outline text.

  • crates/format/src/rtf.rs:63 strips the BOM bytes with strip_prefix before calling the shared sniffer; no panic path.
  • crates/format/src/rtf.rs:192 strips U+FEFF from the decoded text before paragraph parsing, so the mark no longer ends up in the first title.
  • crates/format/src/rtf.rs:633-638: the test places a space and CRLF after the BOM. A case with the BOM directly before {\rtf1 would cover the plain form as well.
  • This relies on the input being decoded as UTF-8 before paragraphs() runs; a non-UTF-8 decode would leave the BOM as three Latin-1 characters.

Claims checked:

  • verified: The RTF sniffer now accepts input that starts with a UTF-8 BOM. (crates/format/src/rtf.rs:63 calls craft_rtf::is_rtf(bytes.strip_prefix(b"\xef\xbb\xbf").unwrap_or(bytes)); test at crates/format/src/rtf.rs:636 asserts sniff_rtf on BOM-prefixed input.)
  • verified: The outline parser no longer treats the BOM as part of the first title. (crates/format/src/rtf.rs:192 strips a leading '\u{feff}' in paragraphs(); crates/format/src/rtf.rs:637 asserts rtf_to_outline yields "Document\n\tCafé\n".)
  • unverified: Both import routes (open and insert) get the fix at the import boundary. (The fix sits inside sniff_rtf (crates/format/src/rtf.rs:63) and paragraphs (crates/format/src/rtf.rs:192), not at a caller boundary. The open and insert callers could not be read to confirm they both go through these function…
  • verified: Both routes still use the pinned shared lexer. (crates/format/src/rtf.rs:63 still delegates to craft_rtf::is_rtf; no Cargo.toml or lockfile change in the PR.)

Reviewed at 18d7537.

Recommendation: merge, after a maintainer's decision.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes something that is broken: wrong result, crash, data loss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant