Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not pass sanitized directories into utils.dirs_match #148

Merged
merged 3 commits into from
Aug 17, 2024

Conversation

neandrake
Copy link
Contributor

The utils.dirs_match() function is not expecting input directories to already be sanitized and can result in failure to properly detect matches with directories.

The init.allowed_dir() function is sanitizing the current working directory before passing as input to utils.dirs_match(), causing failure to detect match with the following setup on a macOS system:

allowed_dirs = {
  '~/.config',
}

And invoking nvim while in ~/.config/nvim working directory.

This change removes init.cwd() which is only ever used twice, one of which is incorrectly in init.allowed_dir(), the other in init.current(). This updates init.current() to sanitize the working directory as is needed, and updates init.allowed_dir() to use the unsanitized working directory.

The `utils.dirs_match()` function is not expecting input directories
to already be sanitized and can result in failure to properly detect
matches with directories.

The `init.allowed_dir()` function is sanitizing the current working
directory before passing as input to `utils.dirs_match()`, causing
failure to detect match with the following setup on a macOS system:

```lua
allowed_dirs = {
  '~/.config',
}
```

And invoking `nvim` while in `~/.config/nvim` working directory.

This change removes `init.cwd()` which is only ever used twice, one of
which is incorrectly in `init.allowed_dir()`, the other in
`init.current()`. This updates `init.current()` to sanitize the working
directory as is needed, and updates `init.allowed_dir()` to use the
unsanitized working directory.
lua/persisted/init.lua Outdated Show resolved Hide resolved
@olimorris
Copy link
Owner

Awesome thank you for this!

@olimorris olimorris merged commit 03990e4 into olimorris:main Aug 17, 2024
4 checks passed
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.

2 participants