yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug?]: Shell drops trailing spaces in parameter expansion alternate values #5366

Open shawnmcknight opened 1 year ago

shawnmcknight commented 1 year ago

Self-service

Describe the bug

When using parameter expansion with alternate values, trailing spaces are being dropped. For example:

FOO=hi && echo ${FOO:+hello }world

should output: hello world

but the output is instead: helloworld

To reproduce

await packageJsonAndInstall({
  scripts: {
    alt: "FOO=hi && echo ${FOO:+hello }world",
  },
});

expect(await yarn(`run`, `alt`)).toBe("hello world\n");

Environment

System:                                                             
  OS: Windows 10 10.0.22623                                         
  CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor                 
Binaries:                                                           
  Node: 18.15.0 - ~\AppData\Local\Temp\xfs-d5211d86\node.CMD        
  Yarn: 4.0.0-rc.42.dev - ~\AppData\Local\Temp\xfs-d5211d86\yarn.CMD
  npm: 9.5.0 - C:\Program Files\nodejs\npm.CMD

Additional context

Running the same in a bash shell: image

yarnbot commented 1 year ago

This issue reproduces on master:

Error: expect(received).toBe(expected) // Object.is equality

- Expected
+ Received

- hello world
+ helloworld

    at module.exports (evalmachine.<anonymous>:8:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
yarnbot commented 1 year ago

This issue reproduces on master:

Error: expect(received).toBe(expected) // Object.is equality

- Expected
+ Received

- hello world
+ helloworld

    at module.exports (evalmachine.<anonymous>:8:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)