Skip to content

fix(web): GB18030 RTF files now preview instead of showing no preview - #42827

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
only21mil:fix/web-rtf-gb18030-preview
Nov 25, 2026
Merged

juliusmarminge merged 2 commits into
pingdotgg:mainfrom
only21mil:fix/web-rtf-gb18030-preview

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

The web file preview's RTF parser (rtfCodePageLabel in apps/web/src/components/files/extendedDocumentPreview.ts) has no entry for Windows code page 54936 (Simplified Chinese GB18030). It falls back to "windows-54936", which TextDecoder rejects, so an RTF file declaring \ansicpg54936 shows "No preview for this file. This rich text code page is not supported." in the Files panel and in attachment previews. A font-table \cpg54936 uses the same helper and, under \fcharset0, decoded as windows-1252 mojibake (for example, 中文 shown as ÖÐÎÄ).

Change

  • Mapped 54936 to the WHATWG "gb18030" label in rtfCodePageLabel (apps/web/src/components/files/extendedDocumentPreview.ts).
  • Added two GB18030 rows to "decodes declared rich text code pages for raw bytes and escaped byte runs" (apps/web/src/components/files/FilePreviewPanel.test.ts): an \ansicpg54936 document covering 2-byte and 4-byte GB18030 sequences plus a \uc2\u20320\'c4\'e3 fallback pair, and a font-table \cpg54936 with \fcharset0 ({\rtf1\ansi{\fonttbl{\f0\fnil\fcharset0\cpg54936 SimSun;}}\f0 \'d6\'d0\'ce\'c4} -> "<p>中文</p>").
  • Added a real-app scenario (scripts/scenarios/rtf-preview-decodes-gb18030.e2e.ts) that opens a GB18030 RTF file (notes.rtf) via quick-open and asserts the decoded preview text.

Scope

Small one-line fix for an obvious bug, so no issue is needed: it adds the missing standard Windows code-page mapping beside the existing GBK, Big5, and Shift_JIS entries, plus unit and scenario coverage. PR #42776 already fixed the same missing mapping in the server's attachment text extractor; this PR fixes the web preview's own copy of the map.

Verification

Setup: An AI agent captured the Browser-panel screenshots against the T3 Code web dev server on Linux (Node v26.13.1), light theme, 2560x1600 viewport, with fresh isolated data on each commit and one synthetic project containing gb18030-note.rtf ({\rtf1\ansi\ansicpg54936 Quarterly notes: \'d6\'d0\'ce\'c4 \'95\'32\'82\'36 \'82\'35\'8f\'33 \uc2\u20320\'c4\'e3 done\par}).

Steps: Open the project → Files panel → click gb18030-note.rtf → maximize the panel (the after capture also sets reading size to 200%).

f99eceb76da 51398e4712f
The Files panel shows "No preview for this file" and "This rich text code page is not supported."
The Files panel shows "No preview for this file" and "This rich text code page is not supported."
The Files panel previews the text "Quarterly notes: 中文 𠀀 龦 你 done".
The Files panel previews the text "Quarterly notes: 中文 𠀀 龦 你 done".

Setup: The repo's scenario tool's own run: 1280x800, fresh isolated app per commit, environment labeled Scenario.

Steps: open thread → Control+P → notes.rtf.

f99eceb76da 51398e4712f
The scenario run shows "No preview for this file" for notes.rtf.
The scenario run shows "No preview for this file" for notes.rtf.
The scenario run previews notes.rtf as "Quarterly notes: 中文 𠀀 龦 你 done".
The scenario run previews notes.rtf as "Quarterly notes: 中文 𠀀 龦 你 done".

Not shown as a glyph in one capture: U+20000 (𠀀) renders as an empty box in the Browser-panel after capture only because that capture browser has no font with CJK Extension B glyphs (the page text holds the correct code point); the scenario head capture renders it.

An AI agent ran the focused RTF code-page test in apps/web/src/components/files/FilePreviewPanel.test.ts on Node v26.13.1:

  • On base (f99eceb76da), the \ansicpg54936 row failed with PreviewError (code: 'rtf-code-page', Test Files 1 failed (1) / Tests 1 failed | 49 skipped (50)).
  • With the 54936 map line removed and the earlier \ansicpg54936 row commented out so it would not fail first, the font-table \cpg54936 row failed with AssertionError: expected '<p>ÖÐÎÄ</p>' to be '<p>中文</p>' (Test Files 1 failed (1) / Tests 1 failed | 49 skipped (50)).
  • On head (51398e4712f), the focused test passed in 3 of 3 runs (Test Files 1 passed (1) / Tests 1 passed | 49 skipped (50)), and the whole FilePreviewPanel.test.ts file passed (Test Files 1 passed (1) / Tests 50 passed (50)).

An AI agent ran vp run scenarios:prove scripts/scenarios/rtf-preview-decodes-gb18030.e2e.ts --base f99eceb76da; it exited 0 (EXIT_CODE=0) with verdict "Proven: the scenario fails on base f99eceb76d and passes on head 51398e4712." On base it failed at expect.toHaveText on the preview body with observed: text [] (match count 0).

An AI agent ran vp run check:changed on head (51398e4712f, 3 files since f99eceb76dac); it exited 0 (EXIT_CODE=0: pass for format, lint, knip 1/2, knip 2/2, typecheck (2 packages), test (1 files), and react compiler (1 files); unused patch check skipped: no dependency files changed).

Generated with Gemini 4 Neon in T3 Code Nightly

@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 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 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 51398e4 and 6b6b662.

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 maps code page 54936 to gb18030. Unit tests cover escaped-byte and font-specific declarations, and a browser test checks decoded text from a GB18030-encoded RTF.

Changes: GB18030 RTF decoding

Layer / File(s) Summary
Code-page mapping and preview validation
apps/web/src/components/files/extendedDocumentPreview.ts, apps/web/src/components/files/FilePreviewPanel.test.ts, scripts/scenarios/rtf-preview-decodes-gb18030.e2e.ts
Code page 54936 maps to gb18030. Unit tests cover escaped bytes with Unicode fallback and a font-specific declaration. The browser test checks decoded preview text.

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

Change: Bug fix

Possibly related PRs

  • pingdotgg/t3code#41514: Changes RTF font code-page selection and shares the code-page lookup behavior and unit-test file.

Suggested labels: bugfix

Suggested reviewers: marve10s, geezoria, macroscopeapp

Merge Risk: Minimal · previous review 51398

GB18030-encoded RTF files should now preview instead of showing "No preview". The change is small and easy to revert, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: GB18030 RTF files now preview instead of showing no preview. It matches the change that maps Windows code page 54936 to the gb18030 label, which the raw summary and ob…
Description check Passed The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives the expected behavior and the failing code path. The Change section lists the map ent…
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: GB18030 RTF files now preview instead of showing no preview. It matches the change that maps Windows code page 54936 to the gb18030 label, which the raw summary and objectives both describe. It uses the conventional commit form and is specific.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives the expected behavior and the failing code path. The Change section lists the map entry and tests. The Scope section explains why no issue is needed. The Verification section gives focused test results, scenario results, and before/after screenshots. The template asks for a model and harness note when an agent did the work, and the description includes one (Gemini 4 Neon in T3 Code Nightly).

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 cef38e4 and 51398e4.

Files selected for processing: 3

  • apps/web/src/components/files/FilePreviewPanel.test.ts
  • apps/web/src/components/files/extendedDocumentPreview.ts
  • scripts/scenarios/rtf-preview-decodes-gb18030.e2e.ts

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

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

Copy link
Copy Markdown
Member

Evidence

Seeded the two exact reported RTF fixtures in a synthetic git project and opened each through Control+P. Both sides used Chromium 156 on Linux, 1280×800, light theme, and fresh databases.

Proven: the scenario fails on base and passes on head. Base rendered font-table text as ÖÐÎÄ and rejected the quarterly notes code page. Head rendered 中文 and opened quarterly notes with the exact expected document text.

Capture Before — 91d6c05ac4 After — 6b6b662978
Font table Before: font-table mojibake After: font-table Chinese
Quarterly notes Before: unsupported code page After: decoded preview
Recording Before After

Scenario and exact fixtures

Visual limitation: installed browser fonts display boxes for 𠀀 and 龦; the rendered iframe text matches Quarterly notes: 中文 𠀀 龦 你 done exactly.

Not shown:

  • Visual glyph shapes for 𠀀 and 龦: installed browser fonts display boxes. Their decoded code points were verified in the real preview iframe's exact text.

@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 25, 2026
@juliusmarminge
juliusmarminge merged commit c991a91 into pingdotgg:main Nov 25, 2026
57 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 25, 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