Skip to content

fix(web): RTF previews read text in an ANSI font as code page 1252 under any document code page - #41514

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
Marve10s:fix/web-rtf-ansi-font-charset
Nov 23, 2026
Merged

juliusmarminge merged 2 commits into
pingdotgg:mainfrom
Marve10s:fix/web-rtf-ansi-font-charset

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

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. 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 (Приâåò).
main:  Expected: "<p>€5 café</p>"  Received: "<p>Ђ5 cafй</p>"
fix:   Tests  45 passed (45)

vp run check:changed upstream/main passes.

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T15:30:25.568506Z 7b021a4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

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.

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

Change: Bug fix

Suggested reviewers: only21mil, tiliakoos, geezoria

Merge Risk: Minimal · previous review 7b021

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 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 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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 593885b and 7b021a4.

Files selected for processing: 2

  • apps/web/src/components/files/FilePreviewPanel.test.ts
  • apps/web/src/components/files/extendedDocumentPreview.ts

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

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

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.

Example Before — 37a70fa041 After — aae7406b9c
Windows-1251 document Before: Ђ5 cafй After: €5 café
Macintosh document Before: pridrûana After: pridržana

Scenario and exact seed files

Not shown:

  • Explicit font-table \cpg overrides and \fontfile isolation were not exercised; this proof covers the two reported rendering failures.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 23, 2026
@juliusmarminge
juliusmarminge merged commit 14c697c into pingdotgg:main Nov 23, 2026
56 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants