Skip to content

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

Open

Description

@trackoor

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/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions