Skip to content

Incorrect pnpm escaping introduced by #9018 #9381

@krrutkow

Description

@krrutkow

Verify latest release

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

pnpm version

No response

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

The example provided in #8980 is sufficient with a change to the invoke.sh script from

ARG='A
B'

to

ARG='A
B != '"'A\nB'"

Describe the Bug

Running invoke.sh demonstrates that ! is escaped to \! by pnpm and is not escaped by node or npm.

-------- node -------
[
  '/usr/bin/node-20',
  '/bug/act.mjs',
  "A\nB != 'A\\nB'"
]
410a4220213d2027415c6e4227

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

> act
> node act.mjs A
B != 'A\nB'

[
  '/usr/bin/node-20',
  '/bug/act.mjs',
  "A\nB != 'A\\nB'"
]
410a4220213d2027415c6e4227

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

> @ act /bug
> node act.mjs "A
B \!= 'A\\nB'"

[
  '/usr/bin/node-20',
  '/bug/act.mjs',
  "A\nB \\!= 'A\\nB'"
]
410a42205c213d2027415c6e4227

Expected Behavior

Prior to #9018 (using pnpm v9.15.4) the ! would not be escaped, and the \n would incorrectly be escaped.

-------- node -------
[
  '/usr/bin/node-20',
  '/bug/act.mjs',
  "A\nB != 'A\\nB'"
]
410a4220213d2027415c6e4227

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

> act
> node act.mjs A
B != 'A\nB'

[
  '/usr/bin/node-20',
  '/bug/act.mjs',
  "A\nB != 'A\\nB'"
]
410a4220213d2027415c6e4227

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

> @ act /bug
> node act.mjs "A\nB != 'A\\nB'"

[
  '/usr/bin/node-20',
  '/bug/act.mjs',
  "A\\nB != 'A\\nB'"
]
415c6e4220213d2027415c6e4227

It is expected that the escaping (and non-escaping) should match that of node/npm invocations.

Which Node.js version are you using?

20.18.3

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, ArchLinux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions