worldmonitor icon indicating copy to clipboard operation
worldmonitor copied to clipboard

fix(parsing): decode & last in all 13 hand-rolled entity decoders (#5436)

Open lspassos1 opened this issue 4 months ago • 1 comments

Summary

Closes #5436.

The entity-decode ordering bug fixed for list-feed-digest's decodeXmlEntities in #5432 existed in every other hand-rolled decoder in the repo: decoding &amp; before the other entity replaces turns the escaped ampersand of &amp;lt; into a live &, which the very next replace consumes as &lt; — one pass decoding two levels. In the strip-then-decode pipelines (seed-security-advisories, seed-global-tenders) a double-escaped &amp;lt;script&amp;gt; survived the tag strip and re-emerged as a live <script> in seeded content.

All 13 decoders reordered so &amp; is decoded last (mirroring the #5432 reference, with the same explanatory comment):

  • 10 seeder/parse scripts: _trade-parse-utils, seed-climate-news, seed-disease-outbreaks, seed-energy-intelligence, seed-fatf-listing, seed-global-tenders, seed-hormuz, seed-regulatory-actions, seed-security-advisories, seed-sovereign-wealth
  • ais-relay.cjs (_decodeRedditEntities)
  • both CountryDeepDivePanel decoders — the panel's private copy was an exact duplicate of the CountryDeepDivePanel-news-utils export and now delegates to it

Details:

  • seed-sovereign-wealth's catch-all &[#\w]+; replace gets a (?!amp;) lookahead so the trailing &amp; decode stays one-level.
  • The two decoders that fed unvalidated numeric refs straight into String.fromCodePoint (seed-energy-intelligence, seed-regulatory-actions — RangeError above 0x10FFFF killed the whole seed run on one malformed ref) now bounds-check via the same decodeNumericReference guard the reference fix uses; out-of-range refs are dropped, astral-plane refs still decode.

Type of change

  • [x] Bug fix

Affected areas

  • [x] News panels / RSS feeds
  • [x] Other: seeder scripts (scripts/seed-*), AIS relay Reddit path, CountryDeepDivePanel

Checklist

  • [ ] Tested on worldmonitor.app variant
  • [ ] Tested on tech.worldmonitor.app variant (if applicable)
  • [ ] New RSS feed domains added to api/rss-proxy.js allowlist (if adding feeds)
  • [x] No API keys or secrets committed
  • [x] TypeScript compiles without errors (npm run typecheck)

Documentation Alignment Checklist

N/A — no documentation claims or generated docs change.

Verification

  • New tests/entity-decode-ordering.test.mts (19 cases): single-level decode (&amp;lt;script&amp;gt; yields the text &lt;script&gt;, never live markup), strip-pipeline re-arm prevention for seed-security-advisories/seed-global-tenders, RangeError guards (&#x110000;, &#9999999999; dropped without throwing; &#128512; → 😀), and plain/singly-escaped input still decodes. RED on the pre-fix code.
  • seed-climate-news and seed-hormuz execute their seed at import time (no main guard), so their decoders carry the fix + comment but are not directly imported by the test — noted here so a future import-safety refactor can add them.
  • Affected existing suites all green (291 tests): regulatory-seed-unit, seed-fatf-listing, energy-spine-seed, security-advisory-source-contract, ais-relay-rss, seed-bundle-resilience-recovery, swf-*, seed-sovereign-wealth-*, country-news-dedupe, nixpacks-seeder-import-graph, seed-ttl-outlives-staleness-fleet.
  • npm run typecheck clean.

Screenshots

N/A — text-parsing change; no UI rendering difference for well-formed content.


Generated by Claude Code

lspassos1 avatar Jul 25 '26 19:07 lspassos1

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldmonitor Ready Ready Preview, Comment Jul 25, 2026 7:41pm

Request Review

vercel[bot] avatar Jul 25 '26 19:07 vercel[bot]

Closing as superseded by #5754, which landed the same fix in a stronger form.

This PR reordered &amp; to last inside each of the 13 hand-rolled decoder chains. #5754 replaces the chains outright with two shared single-pass decoders (scripts/_html-entities.mjs, src/utils/html-entities.ts), which is structurally immune to the ordering bug rather than merely correctly ordered — a future edit cannot reintroduce it. It also covers decoders this PR missed (china-macro, china-policy, cross-strait-activity, usni-fleet-parser, _disease-outbreaks-helpers) and its numeric-reference guard additionally rejects lone surrogates, which this PR's did not.

No action needed; #5436 is fully addressed on main.


Generated by Claude Code

lspassos1 avatar Jul 29 '26 00:07 lspassos1