Skip to content

Multi-line arguments don't get forwarded correctly to scripts #7641

@staticshock

Description

@staticshock

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

8.15.1

Which area(s) of pnpm are affected? (leave empty if unsure)

CLI

Link to the code that reproduces this issue or a replay of the bug

No response

Reproduction steps

Create a package.json with the following content:

{
  "scripts": {
    "go": "node -e 'console.log(process.argv[1])'"
  }
}

Then invoke it with a multi-line arg using all the major package managers:

  1. npm run go $'foo\nbar'
  2. yarn run go $'foo\nbar'
  3. pnpm run go $'foo\nbar'

Describe the Bug

Observe that npm and yarn both correctly preserve the newline in the input arg, and therefore output it across two lines. pnpm, on the other hand, appears to be encoding the output as a javascript string literal and forwarding it with the \n escape sequence instead of a literal newline.

Expected Behavior

npm and yarn are both doing the expected behavior:

$ npm run go $'foo\nbar'

> go
> node -e 'console.log(process.argv[1])' foo
bar

foo
bar

The bug only manifests when using a script inside the package.json. That is, this variation, which bypasses package.json, does not have the bug: pnpm node -e 'console.log(process.argv[1])' $'foo\nbar'

Which Node.js version are you using?

v20.11.0

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions