Skip to content

fix: preserve run script argument boundaries - #7817

Merged
pbrolin47 merged 1 commit into
mermaid-js:developfrom
Adi-Beker:fix-run-args-slicing
Jun 8, 2026
Merged

pbrolin47 merged 1 commit into
mermaid-js:developfrom
Adi-Beker:fix-run-args-slicing

Conversation

@Adi-Beker

Copy link
Copy Markdown
Contributor

Description

This PR fixes argument forwarding in the root run helper script.

The script previously assigned forwarded arguments with args=${@:2}, which converted the remaining positional parameters into a scalar string. This could lose the original argument boundaries when forwarding arguments to Docker, pnpm, or Cypress commands.

This change stores forwarded arguments in a Bash array and expands them safely where needed.

Related Issue

Fixes #7797

Validation

  • Ran bash -n run to verify the script syntax.

@netlify

netlify Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit a396d95
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/6a243f93a9b3bc0008a5d9e2
😎 Deploy Preview https://deploy-preview-7817--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a396d95

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

@mermaid-js/examples

npm i https://pkg.pr.new/@mermaid-js/examples@7817

mermaid

npm i https://pkg.pr.new/mermaid@7817

@mermaid-js/layout-elk

npm i https://pkg.pr.new/@mermaid-js/layout-elk@7817

@mermaid-js/layout-tidy-tree

npm i https://pkg.pr.new/@mermaid-js/layout-tidy-tree@7817

@mermaid-js/mermaid-zenuml

npm i https://pkg.pr.new/@mermaid-js/mermaid-zenuml@7817

@mermaid-js/parser

npm i https://pkg.pr.new/@mermaid-js/parser@7817

@mermaid-js/tiny

npm i https://pkg.pr.new/@mermaid-js/tiny@7817

commit: a396d95

@codecov

codecov Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 2.82%. Comparing base (3e14965) to head (a396d95).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #7817   +/-   ##
=======================================
  Coverage     2.82%   2.82%           
=======================================
  Files          669     669           
  Lines        72527   72527           
  Branches       990     990           
=======================================
  Hits          2048    2048           
  Misses       70479   70479           
Flag Coverage Δ
unit 2.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@argos-ci

argos-ci Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - Jun 6, 2026, 3:55 PM

@Adi-Beker

Copy link
Copy Markdown
Contributor Author

All checks are passing. Happy to adjust the implementation if maintainers prefer a different approach for the pnpm forwarding case.

@knsv-bot knsv-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[sisyphus-bot]

Review: preserve run script argument boundaries

Thanks for picking this up, @Adi-Beker — and for the careful diagnosis on the issue. You correctly identified that the real bug wasn't the ${@:2} slice itself (that part was already fine) but the scalar assignment args=${@:2} collapsing the forwarded arguments into a single whitespace-joined string, which then got re-split (and glob-expanded) at each use site. Switching to a Bash array with quoted expansions is exactly the right fix.

What's working well

  • 🎉 The pnpm case is handled really well. Replacing sh -c "pnpm $args" (interpolating into the command string — fragile, and a shell-injection footgun) with sh -c 'pnpm "$@"' sh "${args[@]}" is the correct, idiomatic way to forward arguments across the nested-shell boundary: $0 becomes the placeholder sh, $1.. become the array elements, and pnpm "$@" preserves every boundary. Arguments containing spaces (e.g. ./run pnpm vitest 'a test name') now survive intact.
  • 🎉 Consistent and complete. All three consumers of args (build, pnpm, cypress) were updated — no stragglers left on the old scalar form — and args=("${@:2}") is the proper array capture. Since the script is #!/usr/bin/env bash with no set -u, the empty-args case (e.g. ./run cypress) expands "${args[@]}" to nothing safely.

Security

I assessed this directly rather than through the usual SVG/XSS pass — there's no rendering surface here. The relevant angle for a shell script is command injection, and this change reduces that surface: it removes the sh -c "pnpm $args" interpolation in favor of passing arguments as positional parameters, so user-supplied args are no longer re-parsed by the inner shell. Net safety improvement. ✅

Notes (non-blocking)

  • 💡 Out of scope for this PR — line 11's name=$(basename $0) has an unquoted $0 (same general class of quoting issue, just for the script's own path). Not worth widening this PR for; flagging only in case you want a quick follow-up someday.
  • On validation: bash -n run confirms syntax, which is a reasonable bar for a Docker wrapper that isn't easily unit-tested. If you have Docker handy, a quick ./run pnpm vitest 'some name with spaces' makes a nice end-to-end sanity check. No changeset is needed here — run is a root dev-tooling helper, not a published package.

Clean, well-targeted fix that resolves the underlying issue. LGTM. 🚀

@pbrolin47
pbrolin47 added this pull request to the merge queue Jun 8, 2026
Merged via the queue into mermaid-js:develop with commit 180b383 Jun 8, 2026
25 checks passed
@mermaid-bot

mermaid-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

@Adi-Beker, Thank you for the contribution!
You are now eligible for a year of Premium account on MermaidChart.
Sign up with your GitHub account to activate.

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.

run: wrong use of array "slicing"

3 participants