Skip to content

fix(cli): quote the cmd.exe command path with real quotes on Windows - #280

Open
KassaSana wants to merge 5 commits into
firecrawl:mainfrom
KassaSana:fix/windows-cmd-command-quoting
Open

KassaSana wants to merge 5 commits into
firecrawl:mainfrom
KassaSana:fix/windows-cmd-command-quoting

Conversation

@KassaSana

@KassaSana KassaSana commented Sep 24, 2026 •

Copy link
Copy Markdown

On Windows, firecrawl setup mcp and every other setup step that runs npx fail when Node is installed under C:\Program Files\, the default location:

'"C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Error: Failed to configure Firecrawl MCP.

Fixes #188

Cause

runClientCommand() starts .cmd shims through cmd.exe /d /s /c and escapes the program path with escapeCmdArg(), giving ^"C:\Program Files\nodejs\npx.cmd^". That escaping is right for arguments, because cmd.exe strips the carets and the program's C runtime sees the quotes. cmd.exe parses the program path itself. There ^" is a literal character, so cmd.exe splits the path at the first space.

Changes

  • Add quoteCmdCommand() and use it for the program path only. It wraps the path in plain quotes. cmd.exe still expands %VAR% and !VAR! inside quotes, so quoteCmdCommand() moves each % and ! outside the quotes and caret-escapes it. Argument escaping is unchanged.
  • Export runClientCommand so tests can call it.
  • Update the mocked win32 test in setup.test.ts. It asserted the broken ^"…^" form, so it passed while the real spawn failed.
  • Add setup-windows-spawn.test.ts. It spawns a real cmd.exe with a .cmd shim under Program Files (x86) and checks that arguments arrive unchanged, including & and ${FIRECRAWL_API_KEY}. It also covers paths containing %USERNAME%.
  • Add a test-windows-spawn CI job on windows-latest that runs that one file on pull requests. The main test job runs on Linux and skips those tests. The new job uses the same pinned action SHAs, read-only contents permission and persist-credentials: false as the other jobs, and takes the pnpm version from packageManager.

This differs from the patch suggested in #188, which changed escapeCmdArg for every argument. With unescaped outer quotes cmd.exe stops stripping the carets, so https://x.dev/mcp?a=1&b=2 would arrive as a=1^&b=2. Thanks to @matheusjosedesouzabispo-blip for pointing to escapeCmdArg.

#187 moves runClientCommand to src/utils/run-client-command.ts with the same escapeCmdArg(resolved) line. If #187 merges first, I'll rebase and apply the same change there.

Testing

Windows 11, Node 26, pnpm 10.12.1:

  • The 3 new real-spawn tests fail before the fix and pass after.
  • End to end, I ran firecrawl setup mcp --project --agent claude-code -y --keyless in a temporary directory. Published 1.24.4 fails with the error above. This branch prints Done! and writes .mcp.json.
  • The full suite has the same 28 failures on main and on this branch. All 28 are in unrelated tests whose path assumptions don't hold on Windows. This PR adds none.

Linux, Node 22: main has 619 passing. This branch has 619 passing plus 3 skipped win32-only tests. pnpm type-check, pnpm build and Prettier pass.

Copilot AI lite review requested due to automatic review settings September 24, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Shadow auto-approve: would not auto-approve because issues were found.

Fix all with cubic | Re-trigger cubic

Comment thread src/commands/setup.ts Resolved
@KassaSana

Copy link
Copy Markdown
Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@KassaSana I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Shadow auto-approve: would not auto-approve because issues were found.

Fix all with cubic | Re-trigger cubic

@KassaSana

Copy link
Copy Markdown
Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@KassaSana I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Fixes Windows cmd.exe quoting for CLI commands by using real quotes on the command token while keeping caret-escaping for arguments, verified by real cmd.exe spawn tests and CI. The fix is focused and clearly beneficial.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Shadow auto-approve: would not auto-approve because issues were found.

Fix all with cubic | Re-trigger cubic

Comment thread .github/workflows/test.yml Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Fixes Windows cmd.exe quoting for CLI command paths by using real quotes on the command token while keeping caret-escaping for arguments, with real cmd.exe spawn tests and a Windows CI job. Bounded, test-verified bug fix.

Re-trigger cubic

@KassaSana

Copy link
Copy Markdown
Author

@developersdigest could you approve the workflow runs when you get a chance? They're waiting on first-time contributor approval, and this PR adds a Windows job that exercises the fix for #188 against a real cmd.exe. Thanks!

runClientCommand() launches .cmd shims such as npx.cmd through
`cmd.exe /d /s /c`, and escaped the resolved program path with the same
escapeCmdArg() used for arguments. That produces ^"C:\Program Files\...^".
For arguments this works, because cmd.exe strips the carets and passes the
quotes on to the program. The program path, though, is parsed by cmd.exe
itself, where ^" is a literal character rather than a quote, so the path
splits at the first space:

  '"C:\Program' is not recognized as an internal or external command

This broke `firecrawl setup mcp`, skills installs and every other setup
step that runs npx whenever Node lives under C:\Program Files, which is
the default install location.

Quote the program path with plain quotes (Windows paths cannot contain
`"`) and leave argument escaping unchanged. Escaping the arguments with
unescaped outer quotes as well would stop the carets from being consumed,
so an argument like `https://host/mcp?a=1&b=2` would arrive as
`a=1^&b=2`.

The existing win32 test mocked child_process and asserted the ^"...^"
form, so it could not see the failure. Update that assertion, and add a
win32-only test that spawns a real cmd.exe with a .cmd shim under
"Program Files (x86)" and checks the argv it receives.

Fixes firecrawl#188
cmd.exe expands %VAR% (and !VAR! under delayed expansion) even inside
double quotes, where a caret is a literal character. With the command
path now in plain quotes, a launcher under a directory such as
`dir%USERNAME%x` was rewritten to the variable's value and failed with
"The system cannot find the path specified" (the previous caret-escaped
form handled this, but only for paths without spaces).

Close the quotes around each % and ! and caret-escape it outside them,
e.g. "C:\a"^%"X"^%"b\npx.cmd", so the path is passed through literally
whether or not it contains spaces. Extend the real cmd.exe test to cover
%USERNAME% in the path, with and without spaces.
setup-windows-spawn.test.ts only runs on win32, and the main test job
runs on ubuntu-latest, so those tests were always skipped in CI. Add a
windows-latest job that runs just that file, reusing the existing Node
and pnpm setup steps.

It targets the one file rather than adding Windows to the main job,
because the full suite has pre-existing Windows-only failures (path
assumptions in setup, credentials and web-defaults tests) that are
identical on main.
@KassaSana
KassaSana force-pushed the fix/windows-cmd-command-quoting branch from 5fcdca5 to 8ef1c4d Compare October 31, 2026 02:17
@KassaSana

Copy link
Copy Markdown
Author

@erikengervall Rebased onto current main. Full suite passes locally (872 passed, the 3 real-cmd.exe tests skip off Windows). This adds a test-windows-spawn job that exercises the #188 fix against a real cmd.exe. Could you approve the workflow runs when you get a chance? Thanks!

@KassaSana

Copy link
Copy Markdown
Author

Following up on this. It's rebased on current main and the review threads are resolved. The new test-windows-spawn job still needs workflow approval to run against a real cmd.exe. Could a maintainer approve the runs and review when you get a chance? Thanks!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The workflow still contains mutable third-party action references at line 55, leaving CI behavior changeable without a reviewed diff.

1 open issue

Review effort: Lite

Comment thread .github/workflows/test.yml Resolved
Match the other jobs: pin actions to the same SHAs, read-only
contents permission, and persist-credentials: false on checkout.

Drop the pnpm version input. pnpm/action-setup throws when it
differs from packageManager in package.json (pnpm@10.34.7), so
the job would fail before running any test.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Fixes Windows command-path quoting and adds real cmd.exe regression coverage in CI. The change is narrowly scoped to setup command execution, with tests covering paths and arguments that previously failed.
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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.

Windows: setup mcp fails with path quoting (C:\Program not recognized, v1.20.0)

2 participants