Skip to content

fix(metadata): decode numeric HTML references with browser scalar rules - #50345

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Afloat16:fix/html-numeric-entities
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Afloat16:fix/html-numeric-entities

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Web pages sometimes write special characters as number codes, like “ for a curly quote. Orca read some of these codes differently from a browser, so link previews and detected port page titles could show invisible junk, broken characters, or the raw code. Now Orca reads them the same way a browser does, so the titles look right.

What Changed

decodeHtmlEntities in src/main/network/page-metadata/html-head-tags.ts is the shared HTML head parser used by link previews (readLinkPreviewMetadata) and workspace port page probes. It now follows the WHATWG rules for numeric character references:

  • 0x80-0x9F map through the Windows-1252 replacement table (27 entries). The unmapped codes 0x81, 0x8D, 0x8F, 0x90 and 0x9D pass through unchanged, as the spec says.
  • �, surrogates (0xD800-0xDFFF), values above 0x10FFFF and numeric overflow become U+FFFD.

Before: <title>&#128; &#x93;quoted&#x94; &#0; &#xD800; &#x110000; &#x1F600;</title> decoded to "\u0080 \u0093quoted\u0094 &#0; \ud800 &#x110000; 😀". That is invisible C1 control characters, a literal &#0;, a lone surrogate, and a literal &#x110000;.

After: it decodes to € “quoted” � � � 😀, which is what a browser shows.

Named-entity decoding and tag scanning are unchanged.

Why

The old code passed every numeric reference straight to String.fromCodePoint. Pages that still use legacy references like &#146; for an apostrophe showed control characters instead. A table was chosen over TextDecoder('windows-1252') so the decoder doesn't depend on ICU in non-Electron runtimes (orcad/server). The table matches TextDecoder('windows-1252') for every code from 0x80 to 0x9F.

Linked Issue

Fixes #50344

Visual Proof

N/A. This changes how text is decoded, not layout or interaction. The exact before/after strings are shown above and are pinned by the regression test.

Testing

  • 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

  • Reproduced on main: the new html-head-tags.test.ts case fails (it gets raw C1 controls, a literal &#0;, a lone surrogate and a literal &#x110000;). It passes with this change.

  • Compared the decoder against the entities package's decodeHTML for every code point from 0 to 0x110010, in decimal and hex, plus overflow: 0 mismatches.

  • Neighbouring suites pass (src/main/network/page-metadata, src/main/link-preview, src/main/ports: 8 files, 17 tests). oxlint, oxfmt, the anti-slop, code-quality and ast-grep gates, and the changed-code quality gate all pass on the touched files.

  • macOS (Node 24). The change is pure string handling with no platform-specific code, so Linux, Windows, SSH and mobile behave the same.

Performance

None. This runs in the main process once per link-preview fetch or port probe, not on a hot path. Median of extractHtmlTitle, old vs new (Node 24):

  • Typical title: 0.0005 ms vs 0.0005 ms.
  • 3 KB of mixed references (decodeHtmlEntities): 0.030 ms vs 0.030 ms.
  • Adversarial 1 MB of references (the link-preview cap): 22.1 ms vs 21.9 ms. This cost was already there before this change.

The change adds one module-level lookup table and a few constant comparisons per numeric reference. It adds no I/O, polling, subprocess work or per-page allocation.

Risk

Level: Low. Only numeric-reference decoding changes, and every consumer only displays the text. findIconHref also decodes hrefs through this function, and mapping invalid references to U+FFFD there matches what a browser does. A plain revert restores the old behavior, and no saved data is involved.

Review

Reviewed against the WHATWG numeric character reference rules and checked against the Windows-1252 decoder for every code from 0x80 to 0x9F. Dropping Number.isInteger is safe because the regex only matches digits, so NaN can't happen and overflow becomes Infinity, which maps to U+FFFD.

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

Security, cross-platform (Linux, Windows, Mac), remote SSH, mobile, backwards compatibility and performance were checked. This is pure string handling in the shared main-process parser, with no protocol or saved-data changes.

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)

Original fix by @Afloat16 in #50345

@coderabbitai

coderabbitai Bot commented Nov 27, 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

  • 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: e7521e71-0753-4d9e-b032-ab85cd9c13f3
Commits

Reviewing files that changed from the base of the PR and between 5a5db77 and b11da71.

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 HTML entity decoder now maps listed numeric references in the 0x80–0x9F range to Windows-1252 characters. It replaces references for zero, surrogate code points, and values above 0x10FFFF with �. A test checks the extracted title for these cases, plus quoted characters, a euro sign, and an emoji.

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 5a5db

This change makes link-preview and detected-port titles decode numeric HTML references the way browsers do, replacing invalid values with the replacement character. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: numeric HTML character references are now decoded with browser scalar rules in the metadata parser. It matches the changeset, which maps C1 references to Windows-1252 …
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #50344), Visual Proof (N/A with a reason), Testing, Performance, Risk with a level, AI Disclos…
Linked Issues check Passed [#50344] requires browser-style numeric character reference decoding in the shared HTML head parser. The diff in src/main/network/page-metadata/html-head-tags.ts meets this for the reported cases:
- A…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes two files. html-head-tags.ts contains the numeric-reference decoding change that [#50344] requests. html-head-tags.test.ts adds one regression test for…
Full details: Title check

Explanation

The title names the main change: numeric HTML character references are now decoded with browser scalar rules in the metadata parser. It matches the changeset, which maps C1 references to Windows-1252 characters and replaces invalid scalars with U+FFFD. The title follows the conventional commit style and is 71 characters long, so it is slightly long but still clear.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #50344), Visual Proof (N/A with a reason), Testing, Performance, Risk with a level, AI Disclosure, Review, the upstream boundary checkbox, Notes, and Checklist. The Testing section names the reproduction input, the platform (Linux x64), and the commands run. Some template items are weak. The Performance section gives a one-line answer. The Risk section gives a revert path. The 'Level' field is set to Low. The Notes section is generic. The Checklist leaves the full lint, typecheck, test, and build gate unchecked, and the author states that this gate is still pending. These gaps do not make the description incomplete.

Full details: Linked Issues check

Explanation

[#50344] requires browser-style numeric character reference decoding in the shared HTML head parser. The diff in src/main/network/page-metadata/html-head-tags.ts meets this for the reported cases:

  • Adds NUMERIC_ENTITY_REPLACEMENTS, which maps the 0x80-0x9F Windows-1252 references to their characters. For example, 0x80 maps to U+20AC and 0x93 maps to U+201C. Unmapped values in this range keep their code point, as in the WHATWG table.
  • Maps code 0, values above 0x10FFFF, and surrogate code points (0xD800-0xDFFF) to U+FFFD.
  • Leaves other valid references decoded through String.fromCodePoint.
    The added test in html-head-tags.test.ts asserts that extractHtmlTitle on the reported input returns exactly '€ “quoted” � � � 😀', which matches the issue's expected title. Named entity handling is unchanged. The diff does not modify readLinkPreviewMetadata or workspace-port-page-probe. Both callers are stated to use the shared parser, but I did not inspect those callers. This does not affect the verdict, because the fix is in the shared function.
Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes two files. html-head-tags.ts contains the numeric-reference decoding change that [#50344] requests. html-head-tags.test.ts adds one regression test for the same reported input. Neither file contains unrelated changes. The PR description's performance, risk, and review sections describe the same change and add no separate code changes.

  • 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: 2e693908-3482-4def-89ad-b94ba8f6f241
Commits

Reviewing files that changed from the base of the PR and between 33dfd04 and 5a5db77.

Files selected for processing: 2

  • src/main/network/page-metadata/html-head-tags.test.ts
  • src/main/network/page-metadata/html-head-tags.ts

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

Link-preview and workspace-port page titles passed numeric character
references straight to String.fromCodePoint, so legacy references such
as &stablyai#146; became invisible C1 controls, &#xD800; produced a lone
surrogate, and &#0; or &#x110000; stayed literal.

Follow the WHATWG numeric character reference rules: 0x80-0x9F map
through the Windows-1252 replacement table, and NUL, surrogates and
values above U+10FFFF become U+FFFD.

Fixes stablyai#50344
@nwparker
nwparker force-pushed the fix/html-numeric-entities branch from 5a5db77 to b11da71 Compare November 27, 2026 05:10
@nwparker
nwparker merged commit 36578be into stablyai:main Nov 27, 2026
55 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]: decode numeric HTML references with browser scalar rules

2 participants