yarnpkg / berry

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

[Bug?]: Directories with spaces break yarn cd $INIT_CWD #6367

Closed AxelEriksson0 closed 4 days ago

AxelEriksson0 commented 4 days ago

Self-service

Describe the bug

Hello!

This is a bit of an edge case, as normally repositories and working directories don't contain spaces. But if you for example have a pipeline job in Jenkins and it creates a temporary folder based on the name of the job, it only picks up the name up to the first space when using cd $INIT_CWD.

Maybe someone could pinpoint the issue, if not I could take a look at it as well.

To reproduce

I created a small repository that shows the issue - https://github.com/AxelEriksson0/directory-with-spaces-break-yarn-init_cwd

Environment

System:
    OS: Linux 6.9 Fedora Linux 40 (Workstation Edition)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  Binaries:
    Node: 21.6.1 - /tmp/xfs-e92e48ad/node
    Yarn: 4.3.1 - /tmp/xfs-e92e48ad/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v21.6.1/bin/npm

Additional context

No response

AxelEriksson0 commented 4 days ago

I guess the issue lies in the cd command not handling spaces unless the entire path is in strings. So perhaps $INIT_CWD should return the path in strings.

arcanis commented 4 days ago

That's a standard shell behaviour - variable interpolation splits content by spaces; that's why it's possible to pass arguments in variables (CFLAGS="-W -Wall"). You need to explicitly wrap your variables around double quotes to disable this behaviour (cd "$DIR", not cd $DIR).

AxelEriksson0 commented 4 days ago

@arcanis you're right. I tried doing that before but what I missed was escaping the quotes. I will close this issue.

(Yarn 4 works great and has definitely been a productivity boost)