Skip to content

pnpm run transforms "\n" to "\\n" #8980

@yoursunny

Description

@yoursunny

Verify latest release

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

pnpm version

9.15.4

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

package.json

{
  "private": true,
  "scripts": {
    "act": "node act.mjs"
  }
}

act.mjs

console.log(process.argv);
console.log(Buffer.from(process.argv[2]).toString("hex"));

invoke.sh

#!/bin/bash
set -eou pipefail
ARG='A
B'

echo
echo '-------- node -------'
node ./act.mjs "$ARG"

echo
echo '-------- npm -------'
npm run act "$ARG"

echo
echo '-------- pnpm -------'
pnpm run act "$ARG"

Describe the Bug

The invoke.sh invokes the script with a command line argument that contains a newline / NL / 0x0A character.

  • When the script is invoked directly or through npm run, the script receives the argument as 'A\nB' which is expected.
  • When the script is invoked through pnpm run, the script receives the argument as 'A\nB', in which the newline character is unexpectedly transformed to its escaped form.
ubuntu@N1:~/bug$ bash invoke.sh 

-------- node -------
[ '/usr/bin/node', '/home/ubuntu/bug/act.mjs', 'A\nB' ]
410a42

-------- npm -------

> act
> node act.mjs A
B

[ '/usr/bin/node', '/home/ubuntu/bug/act.mjs', 'A\nB' ]
410a42

-------- pnpm -------

> @ act /home/ubuntu/bug
> node act.mjs "A\nB"

[ '/usr/bin/node', '/home/ubuntu/bug/act.mjs', 'A\\nB' ]
415c6e42

Expected Behavior

When the script is invoked through pnpm run, it should receive the same argument without escaping.

Which Node.js version are you using?

Node 22.13.0 with npm 10.9.2

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)

Ubuntu 24.04.1

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