Skip to content

Fix trailing slash handling in directory tests#1178

Open
mcollard0 wants to merge 1 commit intoajeetdsouza:mainfrom
mcollard0:br_defect_trailing_slash
Open

Fix trailing slash handling in directory tests#1178
mcollard0 wants to merge 1 commit intoajeetdsouza:mainfrom
mcollard0:br_defect_trailing_slash

Conversation

@mcollard0
Copy link

Resolves issue where `z mydir/` fails even when mydir exists.

Shell built-in directory tests (`[ -d path/ ]`) can fail when paths have trailing slashes. This fix strips trailing slashes before the directory test while preserving the original path for cd.

Changes

  • Fish: Use string replace to strip trailing slashes before -d test
  • Bash: Use `${1%%+(/)}` parameter expansion to remove trailing slashes
  • Zsh: Use `${1%%/##}` parameter expansion to remove trailing slashes
  • POSIX: Loop to strip trailing slashes preserving root directory
  • Tcsh: Use sed to strip trailing slashes before directory test

Key Design Decisions

  • Strip only for testing - trailing slashes removed only for directory existence test
  • Preserve user intent - original path (with trailing slash) still passed to cd
  • Root directory handling - special care to preserve `/` as root directory
  • No breaking changes - backward compatible with paths without trailing slashes

Resolves issue where z mydir/ fails even when mydir exists

Shell built-in directory tests can fail when paths have trailing slashes. This fix strips trailing slashes before the directory test while preserving the original path for cd.

Changes: Fish, Bash, Zsh, POSIX, and Tcsh templates now strip trailing slashes before directory tests
@mcollard0
Copy link
Author

Initial tests are conclusive. No evidence of cancer is not evidence of no cancer. Further testing by peers is requested.

~/.local/bin/zoxide init fish | source
cd zoxide
zoxide: you are already in the only match

cd /
cd zoxide
cd /
cd zoxide/
pwd
/run/media/michael/FAST_ARCHIVE/Programming/zoxide

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