You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(web): RTF previews read text in an ANSI font as code page 1252 under any document code page - #41514
The Files preview shows an RTF file with the wrong letters when its fonts are \fcharset0 (ANSI) and its document code page is not 1252. openRtf in extendedDocumentPreview.ts maps charset 0 to the document code page, but RTF 1.9.1 and LibreOffice map it to 1252. TextEdit writes exactly this on a Mac whose language is not Western:
File
textutil reads
Files preview on main
TextEdit note, \ansicpg1251
€5 café
Ђ5 cafй
Apple's hr.lproj/Trailer.rtf, \mac\ansicpg10000
pridržana
pridrûana
This is the preview side of #41508, which fixes the same reading for the text agents get.
Change
Charset 0 maps to windows-1252. Charset 1 (default) keeps the document code page.
A font-table \cpgN sets that font's code page, using the same lookup as \ansicpg (now one rtfCodePageLabel helper). Without this, the charset-0 change would break a font that names its own code page, such as \fcharset0\cpg1251 under \ansicpg1251, which previews correctly today. A \cpg inside {\*\fontfile …} describes the font file's name and is ignored, and an unknown \cpg leaves the font on its \fcharset.
Scope
This is a small fix for an obvious bug, so it has no issue. It matches #41508 and can land separately from it, as #41277 and #41340 did.
Text before any \f uses the \deff font, as it already does for other character sets. So \deff0 with a \fcharset0 font now previews that text as 1252, where textutil keeps the document code page. TextEdit always writes \f0 before its text.
Verification
Three rows in the existing "decodes declared rich text code pages" case in FilePreviewPanel.test.ts:
an ANSI font under \ansicpg1251, and one in a \mac document, both failing on main;
\fcharset0\cpg1251 beside a font whose \fontfile names code page 1252. It passes on main, and fails with only the charset-0 change or without the \fontfile exception (Приâåò).
Claude Fable 5.2 (high, Claude Agent in T3 Code) found the bug. Claude Opus 5.5 (high) and GPT-6.2 Astra (high, Codex) reproduced it independently. Claude Opus 5.5 (Claude Agent in T3 Code) wrote the fix and test. Claude Opus 5.5 (xhigh), GPT-6.2 Sol, GPT-6.2 Astra (high, Codex), and Claude Fable 5.2 reviewed the patch in T3 Code.
Reviewing files that changed from the base of the PR and between 7b021a4 and aae7406.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The RTF preview now uses a shared code-page lookup for document and font decoding. It handles font-table code pages separately from font-file groups and adds decoding tests for CP1251 and Mac Roman text.
Changes: RTF code-page decoding
Layer / File(s)
Summary
Decoder selection and coverage apps/web/src/components/files/extendedDocumentPreview.ts, apps/web/src/components/files/FilePreviewPanel.test.ts
The preview uses a shared code-page lookup for document and font decoding. Font-table \cpg values set the font decoder except inside \fontfile groups, and unsupported decoder construction leaves the existing font decoder unchanged. Tests cover CP1251, Mac Roman, and font-specific decoding.
This change fixes RTF preview decoding for ANSI fonts under non-1252 document code pages, and the added tests cover the changed behavior. No actionable merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: RTF previews now decode text in an ANSI font as code page 1252 regardless of the document code page. It matches the raw summary, which describes the \fcharset0 mapping…
Description check
The description follows the template. It has Problem, Change, Scope, and Verification sections, and each is filled in with specific content. The problem has a reproduction table and a concrete example…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: RTF previews now decode text in an ANSI font as code page 1252 regardless of the document code page. It matches the raw summary, which describes the \fcharset0 mapping change to windows-1252. The title follows the conventional commit format.
Full details: Description check
Explanation
The description follows the template. It has Problem, Change, Scope, and Verification sections, and each is filled in with specific content. The problem has a reproduction table and a concrete example file. The change explains the charset-0 mapping, the font-table \cpgN handling, and the \fontfile exception. The scope explains why no issue is linked and notes the separate PR #41508. The verification lists the three added test rows and the observed before and after results. It names the models used, as the template asks. The Problem section gives an environment. The template asks for a note on what was not checked, and the description does not include one. This gap is minor.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Opened the two supplied RTF files through the real web app’s Files panel on fresh databases. Chromium/Linux, 1280×800, light theme on both sides. Visually inspected every screenshot; the scenario fails on base and passes on head.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:M30-99 changed lines (additions + deletions).vouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Files preview shows an RTF file with the wrong letters when its fonts are
\fcharset0(ANSI) and its document code page is not 1252.openRtfinextendedDocumentPreview.tsmaps charset 0 to the document code page, but RTF 1.9.1 and LibreOffice map it to 1252. TextEdit writes exactly this on a Mac whose language is not Western:textutilreads\ansicpg1251€5 caféЂ5 cafйhr.lproj/Trailer.rtf,\mac\ansicpg10000pridržanapridrûanaThis is the preview side of #41508, which fixes the same reading for the text agents get.
Change
windows-1252. Charset 1 (default) keeps the document code page.\cpgNsets that font's code page, using the same lookup as\ansicpg(now onertfCodePageLabelhelper). Without this, the charset-0 change would break a font that names its own code page, such as\fcharset0\cpg1251under\ansicpg1251, which previews correctly today. A\cpginside{\*\fontfile …}describes the font file's name and is ignored, and an unknown\cpgleaves the font on its\fcharset.Scope
This is a small fix for an obvious bug, so it has no issue. It matches #41508 and can land separately from it, as #41277 and #41340 did.
Text before any
\fuses the\defffont, as it already does for other character sets. So\deff0with a\fcharset0font now previews that text as 1252, wheretextutilkeeps the document code page. TextEdit always writes\f0before its text.Verification
Three rows in the existing "decodes declared rich text code pages" case in
FilePreviewPanel.test.ts:\ansicpg1251, and one in a\macdocument, both failing on main;\fcharset0\cpg1251beside a font whose\fontfilenames code page 1252. It passes on main, and fails with only the charset-0 change or without the\fontfileexception (Приâåò).vp run check:changed upstream/mainpasses.Claude Fable 5.2 (high, Claude Agent in T3 Code) found the bug. Claude Opus 5.5 (high) and GPT-6.2 Astra (high, Codex) reproduced it independently. Claude Opus 5.5 (Claude Agent in T3 Code) wrote the fix and test. Claude Opus 5.5 (xhigh), GPT-6.2 Sol, GPT-6.2 Astra (high, Codex), and Claude Fable 5.2 reviewed the patch in T3 Code.