Skip to content

fix(gmail): decode legacy numeric and named HTML entities via the shared decoder - #51599

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/gmail-legacy-numeric-entities
Nov 28, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/gmail-legacy-numeric-entities

Conversation

@Pr1p

@Pr1p Pr1p commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Before: 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.
  • After: htmlToText strips 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 shared decodeHtmlEntities from src/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.
  • New test src/main/google/google-html-text.test.ts, including an   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:

Output of htmlToText('<p>&nbsp;Outlook&#146;s &#151; dash &#x2014; &#xD800; &mdash; &amp;x&nbsp;&amp;nbsp;</p>')
Before (main) "Outlook\u0092s \u0097 dash — � &mdash; &x &nbsp;"
After "Outlook’s — dash — � — &x &nbsp;"

Edge cases checked old vs new: &NBSP;, &Amp;, &quot;, &#39;, &#160;, &lt;script&gt;, unknown entities and &amp;nbsp; / &#38;amp; produce the same output as before; &#0;, &#x110000; 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 &mdash; 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 &nbsp; 18.6 / 2.2. The one slower adversarial input is 1 MB made entirely of &#146; (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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

htmlToText now uses the shared decodeHtmlEntities utility after its existing HTML stripping and formatting steps. It replaces &nbsp; with a regular space before decoding. A test checks numeric and named entities, a surrogate reference, and the resulting text.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to b36aa

This fixes Gmail text rendering for legacy numeric references and named entities. It changes only the entity-decoding step and keeps the plain-space handling. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Requirements from #51598 (direct link, open): render &#146; and &#151; as U+2019 and U+2014; render the surrogate reference &#xD800; as U+FFFD; decode named entities such as — instead of leaving…
Out of Scope Changes check Passed The whole-PR diff touches only src/main/google/google-html-text.ts and its new test. The inline entity branch is replaced by the shared decoder, which the issue targets. The pre-decode replacement of …
Title check Passed The title names the main change: Gmail HTML-to-text now decodes legacy numeric and named HTML entities through the shared decoder. The changeset matches this, since google-html-text.ts delegates to de…
Description check Passed The description follows the repository template and fills in its main sections. It explains the user-facing before and after, the mechanism (reuse of the shared decoder), and the reason for the change…
Full details: Linked Issues check

Explanation

Requirements from #51598 (direct link, open): render &#146; and &#151; as U+2019 and U+2014; render the surrogate reference &#xD800; as U+FFFD; decode named entities such as &mdash; instead of leaving them literal; keep unknown names literal. At head, src/main/google/google-html-text.ts delegates to decodeHtmlEntities from src/shared/text/html-entities.ts, as shown in the whole-PR diff from merge base aa74a6c. The new test src/main/google/google-html-text.test.ts feeds '<p>&nbsp;Outlook&#146;s &#151; dash &#x2014; &#xD800; &mdash; &amp;x&nbsp;&amp;nbsp;</p>' and expects 'Outlook’s — dash — � — &x &nbsp;'. Under the decoder behavior recorded in the previous review, this output matches the requirements. The head change since the previous review replaces the literal &nbsp; with a plain space before decoding. &amp;nbsp; is not matched by that replacement, so it decodes to literal '&nbsp;', as the issue requires for unknown names. Limits: html-entities.ts was not re-read in this pass, so the decoder behavior relies on the previous review. The test run was not executed here and rests on the author's report.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff touches only src/main/google/google-html-text.ts and its new test. The inline entity branch is replaced by the shared decoder, which the issue targets. The pre-decode replacement of &nbsp; with a plain space keeps the prior line-end trimming behavior, and the code comment states this reason. The tag-removal and whitespace-cleanup steps are unchanged. The test exercises only the issue cases. No unrelated change was found in the reviewed diff.

Full details: Title check

Explanation

The title names the main change: Gmail HTML-to-text now decodes legacy numeric and named HTML entities through the shared decoder. The changeset matches this, since google-html-text.ts delegates to decodeHtmlEntities and adds a test for those cases. The title is 80 characters, which is slightly long, but it stays specific and on topic.

Full details: Description check

Explanation

The description follows the repository template and fills in its main sections. It explains the user-facing before and after, the mechanism (reuse of the shared decoder), and the reason for the change. It links issue #51598, gives a before/after table, a performance rationale, and a risk level with a revert plan. The Visual Proof N/A reason is given. Minor gaps: the ELI5 and several sections are long for the template's guidance, the AI Disclosure section is left blank (it is internal-only, so it may not apply), and the final lint/typecheck/test/build checklist item is unchecked, which the author should confirm before merge.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 105b3c02-934f-4e70-8e4d-997b2bbf83b7
Commits

Reviewing files that changed from the base of the PR and between fb5c349 and b36aa65.

Files selected for processing: 2

  • src/main/google/google-html-text.test.ts
  • src/main/google/google-html-text.ts

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

…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 &mdash; 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
&nbsp; still becomes a plain space so the line-end trim strips it.

Fixes stablyai#51598

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/gmail-legacy-numeric-entities branch from fb5c349 to b36aa65 Compare November 28, 2026 08:26
@nwparker nwparker changed the title fix(gmail): read legacy numeric entities through the shared HTML decoder fix(gmail): decode legacy numeric and named HTML entities via the shared decoder Nov 28, 2026
@nwparker
nwparker merged commit 48aa41c into stablyai:main Nov 28, 2026
55 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: orca gmail read shows control characters for legacy numeric entities in Outlook and Word mail

2 participants