Skip to content

fix: cd resolves .. against $PWD without re-stat'ing the cwd#195

Open
avaer wants to merge 1 commit into
vercel-labs:mainfrom
avaer:fix/cd
Open

fix: cd resolves .. against $PWD without re-stat'ing the cwd#195
avaer wants to merge 1 commit into
vercel-labs:mainfrom
avaer:fix/cd

Conversation

@avaer

@avaer avaer commented Apr 18, 2026

Copy link
Copy Markdown

The cd builtin walked every component of the target path — including those of ctx.state.cwd — calling fs.stat on each. If the current working directory had been removed (e.g. rm -rf $PWD), cd .. would fail with "No such file or directory" because stat'ing the deleted cwd aborted the walk before .. could pop it.

Real bash uses logical (-L) semantics: $PWD anchors resolution and is not re-stat'd, so cd .. from a deleted cwd resolves textually to the parent. Intermediate components from the user-supplied target still get stat'd, so cd nonexistent/.. continues to error like bash.

Seed the resolution stack from ctx.state.cwd for relative targets, pop on .., and stat only components newly pushed by the target. Adds unit tests for deleted-cwd escape plus intermediate-missing errors, and comparison tests asserting parity with real bash.

@vercel

vercel Bot commented Apr 18, 2026

Copy link
Copy Markdown

@avaer is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant