bun icon indicating copy to clipboard operation
bun copied to clipboard

Quotation marks ignored for arguments when running `package.json` scripts | `'foo bar'` -> `foo`, `bar`

Open Cow258 opened this issue 8 months ago • 0 comments

What version of Bun is running?

1.1.17+bb66bba1b

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

When running scripts defined in package.json that include arguments with whitespace within quotation marks, Bun.js appears to ignore the quotes, splitting the arguments incorrectly.

Steps to Reproduce:

  1. Create a package.json file with the following content:

    {
      "name": "bun-bug",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "args": "bun ./args.js"
      },
      "keywords": [],
      "author": "",
      "license": "ISC"
    }
    
  2. Create an args.js file with the following content:

    const [, , ...args] = process.argv;
    console.log(args);
    
  3. Run the script with arguments that include whitespace within quotation marks using Bash:

    bun run args "abc def" "ghi"
    

Actual Behavior:

The script splits the quoted arguments, ignoring the quotes:

> bun args 'abc def' 'hig'
$ bun ./args.js abc def hig
[ "abc", "def", "hig" ]

What is the expected behavior?

The script should correctly interpret the quoted arguments as single arguments, preserving the whitespace:

> bun args 'abc def' 'hig'
$ bun ./args.js 'abc def' hig
[ "abc def", "hig" ]

What do you see instead?

No response

Additional information

If you run the code directly it fine

> bun ./args.js 'abc def' 'ghi'
[ "abc def", "ghi" ]

Also work fine on npm,yarn,pnpm

> npm run args 'abc def' 'ghi'

> [email protected] args
> bun ./args.js abc def ghi

[ "abc def", "ghi" ]
> yarn args 'abc def' 'ghi'
yarn run v1.22.19
$ bun ./args.js 'abc def' ghi
[ "abc def", "ghi" ]
✨  Done in 0.04s.
> pnpm args 'abc def' 'ghi'

> [email protected] args /Users/cowboyho/Documents/git/cow258/bun-bug
> bun ./args.js "abc def" "ghi"

[ "abc def", "ghi" ]

Cow258 avatar Jun 28 '24 11:06 Cow258