bun icon indicating copy to clipboard operation
bun copied to clipboard

Spaces and quotes aren't handled correctly by bun run

Open KishanBagaria opened this issue 4 years ago • 4 comments
trafficstars

package.json:

{
  "scripts": {
    "argv": "node -e 'console.log(process.argv)'"
  }
}
Screenshot 2021-11-05 at 1 55 05 AM

KishanBagaria avatar Nov 04 '21 20:11 KishanBagaria

working on a fix

Jarred-Sumner avatar Nov 05 '21 02:11 Jarred-Sumner

looks like it's not fully identical to npm behavior (i've to use \" instead of just "):

(this is fish)

KishanBagaria avatar Nov 05 '21 21:11 KishanBagaria

Not sure if the following issue is related:

❯ bat -p package.json 
{
  "name": "blank",
  "version": "0.0.3",
  "module": "src/index.js",
  "scripts": {
    "demo": "echo \"test\""
  },
  "devDependencies": {
    "bun-types": "latest"
  }
}

❯ npm run demo

> [email protected] demo
> echo "test"

test

❯ bun run demo
$ echo \"test\"
"test"

Basically npm does JSON parsing but bun doesn't seem to do it.

kidonng avatar Jul 27 '22 20:07 kidonng

Thanks for reproducing, @kidonng, confirmed it's still an issue as of 0.2.2. We'll get it fixed.

Electroid avatar Nov 01 '22 18:11 Electroid

Confirming this is still an issue with 0.5.9:

 "scripts": {
        "start": "bun run src/app.ts",
        "add:article": "curl -X POST -H 'Content-Type: application/json' -d '{\"id\":1,\"title\":\"Test article\",\"body\":\"Test body\"}' http://localhost:4000/articles/"
    }

Running this won’t work with Bun:

$ bun run add:article
$ curl -X POST -H 'Content-Type: application/json' -d '{\"id\":1,\"title\":\"Test article\",\"body\":\"Test body\"}' http://localhost:4000/articles/
{
  "title": "Bad Request",
  "status": 400,
  "detail": "Unable to parse JSON: JSON Parse error: Unrecognized token '\\'"
}

But it does with npm:

$ npm run add:article

> @ add:article
> curl -X POST -H 'Content-Type: application/json' -d '{"id":1,"title":"Test article","body":"Test body"}' http://localhost:4000/articles/

The reason is clearly that Bun doesn’t parse JSON as stated above.

lutzissler avatar Apr 12 '23 14:04 lutzissler