Tarrasch / zsh-autoenv

Autoenv for zsh
700 stars 30 forks source link

Modifies `_autoenv_get_file_upwards` to not dereference symlinks. #73

Closed rspeed closed 7 years ago

rspeed commented 7 years ago

This prevents issues where symlinked autoenv scripts use $0. When a shell enters the directory holding the autoenv scripts, it works as expected with $0 being the path to the symlink. However, if the shell enters one of its child directories the path to the script is dereferenced, and $0 is instead the path to the symlink's target.

The fix is quite simple. From man 1 zshexpn:

A – Turn a file name into an absolute path as the 'a' modifier does, and then pass the result through the realpath(3) library function to resolve symbolic links.

So I just replaced :A with :a.

Note: Symlinks are dereferenced elsewhere for authorization, so that behavior is unchanged.

blueyed commented 7 years ago

Thanks!

Sorry, I've missed that before.

Do you think you could add a test for that?

rspeed commented 7 years ago

I'm not familiar with this testing framework, but it shouldn't be too hard to figure out.

Edit: Well, it probably would be if I could figure out why I can't get the tests to run. :\

rspeed commented 7 years ago

Sorry, I'm not having much luck here. I think what you'll need to build a regression test is to add another ZDOTDIR which uses symlinked enter/exit scripts.

Also, I think part of the issues I've been having are due to the tests assuming that cram uses a path matching the pattern /tmp/cramtests-*, but that isn't the case on macOS.

blueyed commented 7 years ago

Oh, thanks for notifying. Generally make test should work IIRC.

As for the test, I could assume to have a separate test case for this, by building the file structure accordingly, but have not looked into it.

I guess you could also just use your branch, until someone of us comes to the test.. ;)

blueyed commented 7 years ago

A fix for the issues with the tests on MacOS would be nice to have btw (in a new PR then).

blueyed commented 7 years ago

Added a test.

blueyed commented 7 years ago

Thanks!

blueyed commented 7 years ago

Also fixed the README recipe: 9074633.