yarnpkg / yarnpkg/berry

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

Open
#5,366 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug reproducible
Dominant language
TypeScript
Stars
8.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Self-service
  • I'd be willing to implement a fix
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied JavaScript reproduction with yarn run alt and compare its output with the expected hello world\n. Trace the shell parameter-expansion handling for alternate values, then add coverage for the trailing-space case and confirm the command preserves the space.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, shell, typescript
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.