fix(parsing): decode & last in all 13 hand-rolled entity decoders (#5436)
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 & before the other entity replaces turns the escaped ampersand of &lt; into a live &, which the very next replace consumes as < — one pass decoding two levels. In the strip-then-decode pipelines (seed-security-advisories, seed-global-tenders) a double-escaped &lt;script&gt; survived the tag strip and re-emerged as a live <script> in seeded content.
All 13 decoders reordered so & 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
CountryDeepDivePaneldecoders — the panel's private copy was an exact duplicate of theCountryDeepDivePanel-news-utilsexport and now delegates to it
Details:
seed-sovereign-wealth's catch-all&[#\w]+;replace gets a(?!amp;)lookahead so the trailing&decode stays one-level.- The two decoders that fed unvalidated numeric refs straight into
String.fromCodePoint(seed-energy-intelligence,seed-regulatory-actions—RangeErrorabove0x10FFFFkilled the whole seed run on one malformed ref) now bounds-check via the samedecodeNumericReferenceguard 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.jsallowlist (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 (&lt;script&gt;yields the text<script>, never live markup), strip-pipeline re-arm prevention forseed-security-advisories/seed-global-tenders,RangeErrorguards (�,�dropped without throwing;😀→ 😀), and plain/singly-escaped input still decodes. RED on the pre-fix code. seed-climate-newsandseed-hormuzexecute 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 typecheckclean.
Screenshots
N/A — text-parsing change; no UI rendering difference for well-formed content.
Generated by Claude Code
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| worldmonitor | Preview, Comment | Jul 25, 2026 7:41pm |
Closing as superseded by #5754, which landed the same fix in a stronger form.
This PR reordered & 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