Repository navigation
fix(gmail): decode legacy numeric and named HTML entities via the shared decoder - #51599
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
…red decoder htmlToText decoded entities with its own small table, so mail from Outlook or Word showed C1 control characters for &stablyai#146; and &stablyai#151;, common named entities such as — stayed literal, and a surrogate reference produced a broken string. It now strips tags as before and runs the shared decodeHtmlEntities, which maps Windows-1252 references to their characters and replaces unusable ones with U+FFFD. The named still becomes a plain space so the line-end trim strips it. Fixes stablyai#51598 Co-authored-by: Neil <[email protected]>
fb5c349 to
b36aa65
Compare
ELI5
Emails written in Outlook or Word often store punctuation like curly apostrophes and long dashes as old-style numeric codes. Orca's Gmail reader turned those codes into invisible junk characters and left names like
—as raw text. Orca now uses the same decoder as the rest of the app, so those emails read correctly.What Changed
htmlToText(src/main/google/google-html-text.ts, used for Gmail snippets and HTML-only message bodies) had its own entity table with six names.’and—became C1 control characters U+0092 / U+0097,—/’/…stayed literal, a surrogate reference like�produced a lone surrogate, and�or out-of-range values were silently dropped.htmlToTextstrips tags as before, maps the named to a plain space (so the line-end trim still strips it, matching the old output), then runs the shareddecodeHtmlEntitiesfromsrc/shared/text/html-entities.ts. Windows-1252 references decode to ’ — € etc., the common named entities decode, and unusable references become U+FFFD as the HTML spec says.src/main/google/google-html-text.test.ts, including an&nbsp;case that guards against double decoding.Why
The local decoder was a smaller duplicate of the shared one, missing the Windows-1252 table, U+FFFD handling and most named entities. Reusing the shared decoder fixes all three gaps and removes the duplicate instead of growing it.
Linked Issue
Fixes #51598
Visual Proof
N/A for screenshots: this is plain-text output from the main process (Gmail snippets/bodies), with no UI layout change. Before/after of the same input, from the new test run against main's code and this branch:
htmlToText('<p> Outlook’s — dash — � — &x &nbsp;</p>')"Outlook\u0092s \u0097 dash — � — &x ""Outlook’s — dash — � — &x "Edge cases checked old vs new:
&NBSP;,&Amp;,",', ,<script>, unknown entities and&nbsp;/&amp;produce the same output as before;�,�and surrogates now give U+FFFD instead of nothing or a lone surrogate.Testing
Reproduced: the new test fails with main's
google-html-text.ts(C1 controls and raw—in the output) and passes on this branch.vitest run src/main/google/google-html-text.test.ts src/main/google/google-gmail*.test.ts src/shared/text: 8 files, 33 tests pass.oxlint,
oxfmt --check, anti-slop oxlint, code-quality native plugins oxlint, ast-grep and the changed-code quality gate are clean on the touched files.Platform-independent string code; verified on macOS.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
None, because this runs in the main process on demand per Gmail read or change batch, not on a hot path, and adds no I/O. Benchmarked old vs new (avg ms per call): 78-char snippet 0.0007 / 0.0006; 200 KB typical body 1.38 / 1.16; 1 MB of named entities 28.5 / 11.6; 1 MB of surrogates 17.1 / 9.9; 1 MB of interleaved
18.6 / 2.2. The one slower adversarial input is 1 MB made entirely of’(13.3 / 22.2), still below main's worst case (40 ms max vs 30 ms max on the branch). Not renderer/store code, so no per-item fanout.Risk
Level: Low
Output text changes only: Windows-1252 references and common named entities now decode, and invalid references show U+FFFD instead of disappearing. Callers (gmail-changes snippet trigger matching, gmail-read snippet, gmail-message body fallback) do not persist or round-trip this text. Back out with a plain revert.
Review
Original fix by @Pr1p in #51599; authorship preserved on the commit.
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)