@actions/exec: `exec(commandLine)` drops `""` arguments and trims trailing spaces of the last argument

Open Beginner friendly
#2,569 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@bardrop is already working on this.

Since Nov 12, 2026.

  • #2577 by @bardrop — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
cli, devtools

Research direction

Start with packages/exec/src/toolrunner.ts and inspect argStringToArray, especially how it handles empty quoted arguments and the final argument. Reproduce the examples from the issue with exec.exec or exec.getExecOutput; done means empty arguments and trailing spaces are preserved in all three cases.

Written by the indexing model from the issue text.

Description

Describe the bug
When exec.exec (or exec.getExecOutput) is called with the command and arguments in a single commandLine string, argStringToArray silently drops any empty double-quoted argument ("") and trims trailing whitespace from the last argument only. A command like ssh-keygen -N "" -f key runs as ssh-keygen -N -f key, causing -f to be consumed as the value of -N.

To Reproduce

// repro.mjs
import * as exec from '@actions/exec'
const show = 'node -e "console.log(JSON.stringify(process.argv.slice(1)))" --'
await exec.exec(`${show} -N "" -f key`)
await exec.exec(`${show} -m "fix typo "`)
await exec.exec(`${show} -m "fix typo " x`)
npm i @actions/exec
node repro.mjs

Actual output:

[command]/usr/bin/node -e console.log(JSON.stringify(process.argv.slice(1))) -- -N -f key
["-N","-f","key"]
[command]/usr/bin/node -e console.log(JSON.stringify(process.argv.slice(1))) -- -m fix typo
["-m","fix typo"]
[command]/usr/bin/node -e console.log(JSON.stringify(process.argv.slice(1))) -- -m fix typo  x
["-m","fix typo ","x"]

Expected behavior

["-N","","-f","key"]
["-m","fix typo "]
["-m","fix typo ","x"]

Screenshots
Not applicable.

Desktop (please complete the following information):

  • OS: Linux x86_64
  • Browser: N/A
  • Version: @actions/exec 3.0.0 (actions/toolkit main 0c3a9c3), Node.js v26.13.0

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: N/A
  • Version: N/A

Additional context
In packages/exec/src/toolrunner.ts, argStringToArray only pushes an argument when arg.length > 0 (so "" is discarded), and the final push after the loop uses arg.trim() while earlier pushes do not.

Credit: https://ucsbplse.github.io/

Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
Avg merge
15m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from actions/toolkit

All issues in actions/toolkit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.