Skip to content

fix(legacy-html,man-page,sitemap): treat $$, $&, $` and $' in values as literal text - #1195

Closed
Jbansal2 wants to merge 1 commit into
nodejs:mainfrom
Jbansal2:fix/legacy-html-dollar-replacement
Closed

Jbansal2 wants to merge 1 commit into
nodejs:mainfrom
Jbansal2:fix/legacy-html-dollar-replacement

Conversation

@Jbansal2

@Jbansal2 Jbansal2 commented Oct 28, 2026 •

Copy link
Copy Markdown

Summary

String.prototype.replace(placeholder, value) treats some $ sequences in a string second argument as replacement patterns:

In the value Becomes
$$ $
$& the matched placeholder
$` everything in the template before the placeholder
$' everything in the template after it

Page content, navigation, man page options/environment text, and sitemap URL fields are filled this way, so any of those sequences in the source produces broken output. This already shows on nodejs.org: the Makefile example in C++ addons has $$(command -v node), rendered as $(command -v node) — a literal $ lost.

  • Passes each value through a replacer function (.replace(placeholder, () => value)) instead, since a function's return value is inserted as-is without $-pattern handling.
  • Fixes packages/node-legacy/src/legacy-html/utils/replaceTemplateValues.mjs (used by both legacy-html and legacy-html-all).
  • Fixes the same pattern in packages/node/src/man-page/generate.mjs and packages/react/src/sitemap/generate.mjs.
  • Adds replaceTemplateValues.test.mjs covering $$, $&, $` and $' in both content and nav.
  • Adds a changeset.

Fixes #1181

Test plan

  • node --test packages/node-legacy/src/legacy-html/utils/__tests__/replaceTemplateValues.test.mjs passes
  • npm run test — no new failures introduced (pre-existing unrelated failures on this environment are in core/jsx-ast/highlighter tests, untouched by this change)
  • npx oxlint clean on changed files
  • npx oxfmt --check clean on changed files
  • Manually reproduced the bug with the snippet from the issue before the fix, confirmed it's gone after

@Jbansal2
Jbansal2 requested a review from a team as a code owner October 28, 2026 09:54
@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
api-docs-tooling Ready Ready Preview Oct 28, 2026 9:58am UTC

Request Review

…as literal text

String.prototype.replace(placeholder, value) treats some $ sequences in a
string replacement as patterns ($$ -> $, $& -> the match, $` / $' -> the
template before/after the match). Page content, navigation, man page
options/environment text, and sitemap URL fields are filled this way, so
any of those sequences in the source produced broken output (e.g. the
addons.md Makefile example $$(command -v node) rendered with one $
missing).

Pass each value through a replacer function instead, since a function's
return value is inserted as-is.

Fixes nodejs#1181
@btea

btea commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

It's a duplicate of #1186.

@ovflowd

ovflowd commented Oct 28, 2026

Copy link
Copy Markdown
Member

Duplicate of #1186

@ovflowd ovflowd marked this as a duplicate of #1186 Oct 28, 2026
@ovflowd ovflowd closed this Oct 28, 2026

This branch was successfully deployed

1 active deployment
Preview – api-docs-tooling — 0cd7414b Deployed Oct 28, 2026 by vercel[bot]
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.

legacy-html: $$ in the docs is rendered as $

3 participants