Skip to content

Expand ~/ in whitelist paths#931

Merged
zimbatm merged 1 commit intodirenv:masterfrom
erikw:feature/tilde_path_expansion
Apr 17, 2022
Merged

Expand ~/ in whitelist paths#931
zimbatm merged 1 commit intodirenv:masterfrom
erikw:feature/tilde_path_expansion

Conversation

@erikw
Copy link
Copy Markdown
Contributor

@erikw erikw commented Apr 15, 2022

Expand a path string prefixed with ~/ to the current user's home directory.

Example: if current user is user1 with home directory in /home/user1,
then ~/project -> /home/user1/project

It's useful to allow paths with ~/, so that direnv.toml can be reused via
dotfiles repos across systems with different standard home paths
(compare Linux /home and macOS /Users).

Feedback is welcome e.g. if/how this should be tested. For now manual
testing of prefix & exact has been done confirming that full paths as
well as ~/-paths works.

I looked here for how to expand tilde:
https://gist.github.com/miguelmota/9ab72c5e342f833123c0b5cfd5aca468

I also found a third party module that expands tilde
https://github.com/prep/tilde
that we can swap in instead of the expandTildePath method in this PR
if desired. I assumed the project would like to minimize dependencies
and made this simple function instead.

Feel free to amend or push more commits to the PR if wanted!

Fixes #926

@erikw erikw force-pushed the feature/tilde_path_expansion branch from 12059ba to 6cc1274 Compare April 15, 2022 08:27
Expand a path string prefixed with ~/ to the current user's home directory.

Example: if current user is `user1` with home directory in `/home/user1`,
then `~/project` -> `/home/user1/project`

It's useful to allow paths with `~/`,  so that `direnv.toml` can be reused via
dotfiles repos across systems with different standard home paths
(compare Linux `/home` and macOS `/Users`).

Feedback is welcome e.g. if/how this should be tested. For now manual
testing of prefix & exact has been done confirming that full paths as
well as `~/`-paths works.

I looked here for how to expand tilde:
 https://gist.github.com/miguelmota/9ab72c5e342f833123c0b5cfd5aca468

I also found a third party module that expands tilde
https://github.com/prep/tilde
that we can swap in instead of the `expandTildePath` method in this PR
if desired. I assumed the project would like to minimize dependencies
and made this simple function instead.

Fixes direnv#926
@erikw erikw force-pushed the feature/tilde_path_expansion branch from 6cc1274 to 7530409 Compare April 15, 2022 08:29
@zimbatm zimbatm merged commit d2c5d88 into direnv:master Apr 17, 2022
@zimbatm
Copy link
Copy Markdown
Member

zimbatm commented Apr 17, 2022

thanks!

@erikw erikw deleted the feature/tilde_path_expansion branch April 17, 2022 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Allow flexible whitelist by allowing ~/ or $HOME expansion

2 participants