Skip to content

fix(downloads): strip shell comments when copying download snippets - #9352

Open
rxliuli wants to merge 1 commit into
nodejs:mainfrom
rxliuli:fix/strip-comments-on-copy
Open

rxliuli wants to merge 1 commit into
nodejs:mainfrom
rxliuli:fix/strip-comments-on-copy

Conversation

@rxliuli

@rxliuli rxliuli commented Nov 28, 2026

Copy link
Copy Markdown

Description

Since macOS Catalina, the default interactive shell on macOS is zsh, where INTERACTIVE_COMMENTS is disabled by default. Clicking Copy to clipboard on any download snippet at https://nodejs.org/en/download and pasting it into Terminal.app emits zsh: command not found: # for every comment line and passes inline # Should print "..." comments as literal CLI arguments.

This PR keeps the explanatory # comments visible in the rendered code box for readability, while stripping shell # comments from the clipboard text when copying download snippets:

  • Adds an optional copyText?: string prop to BaseCodeBox (and forwards it through CodeBox), preserving existing containerRef.current?.textContent behavior for all other callers.
  • Adds stripShellComments() in apps/site/util/download/snippet.ts to remove full-line # comments and unquoted trailing inline # comments while preserving # inside single/double/backtick quotes and parameter expansions (e.g. ${VAR#prefix}), and collapsing redundant blank lines.
  • Updates ReleaseCodeBox to pass copyText={stripShellComments(parsedContent)} to CodeBox.
  • Adds unit tests for both stripShellComments and BaseCodeBox's copyText prop, plus a changeset for @node-core/ui-components.

Validation

  • Added unit tests in apps/site/util/__tests__/snippet.test.mjs and packages/ui-components/src/Common/BaseCodeBox/__tests__/index.test.jsx.
  • Ran pnpm format, pnpm test, pnpm lint, pnpm lint:types, and pnpm build — all passed with zero errors.

Related Issues

Refs #9350

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing.
  • I have run pnpm build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@rxliuli
rxliuli requested a review from a team as a code owner November 28, 2026 11:51
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
nodejs-org Ready Ready Preview Nov 28, 2026 11:52am UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 6fae26f8 Deployed Nov 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.

1 participant