-
-
Notifications
You must be signed in to change notification settings - Fork 624
fix(#2004): remove unintentional captures in path_to_matching_str #2005
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the case for underscores and dashes, however there is still potential for other magic regex characters to cause an issue.
A more complete solution might be for path_relative
to use string.find (plain) and string.sub to extract the relative path without needing to resort to regexes.
Are you keen to make that change?
lua/nvim-tree/utils.lua
Outdated
@@ -12,7 +12,7 @@ M.is_wsl = vim.fn.has "wsl" == 1 | |||
M.is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1 | |||
|
|||
function M.path_to_matching_str(path) | |||
return path:gsub("(%-)", "(%%-)"):gsub("(%.)", "(%%.)"):gsub("(%_)", "(%%_)") | |||
return path:gsub("(%-)", "%%-"):gsub("(%.)", "%%."):gsub("(%_)", "%%_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That definitely fixes it. Those captures weren't necessary.
Hmm.. looks like string.find expects a pattern so there's no avoiding of striping the escape characters. From the manual:
Is there a version that's straigthforward string match? I tried |
You can use the third argument |
463f0e6
to
9222462
Compare
Updated PR. I kept the original path_to_matching_str (with captures removed) for reference |
No need; please remove. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for going the extra mile on this one.
There are a lot of windows standard paths that contain magic characters and this fix will take care of all of them.
lua/nvim-tree/utils.lua
Outdated
local p, _ = path:gsub("^" .. M.path_to_matching_str(M.path_add_trailing(relative_to)), "") | ||
local _, r = path:find(M.path_add_trailing(relative_to), 1, true) | ||
local p = path | ||
if r and r < p:len() then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good... except when there is a trailing slash.
See test case attached.
2005-test.lua.gz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test cases. Just pushed the fix. previously version if relative == path, I kept the path but to match the original gsub version, the code now just returns ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem, thanks for the excellent plugin!
…tring to avoid using regex. - This removed the original gsub with unintentional captures in path_to_matching_str - The original regex based code captures create a limit where input path cannot have more than 32 special charactors ( `.` , `_` or `-`)
9222462
to
418878b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution
fixes #2004
The captures creates a limit where input path cannot have more than 32 special charactors (
.
,_
or-
)