-
-
Notifications
You must be signed in to change notification settings - Fork 609
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(#2961): windows: escape brackets and parentheses when opening file #2962
Conversation
@@ -59,6 +59,17 @@ function M.path_basename(path) | |||
return path:sub(i + 1, #path) | |||
end | |||
|
|||
--- Check if there are parentheses before brackets, it causes problems for windows. | |||
--- Refer to issue #2862 and #2961 for more details. | |||
local function has_parentheses_and_brackets(path) |
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.
Great work fixing this one.
--- Escapes special characters in string if windows else returns unmodified string. | ||
---@param path string | ||
---@return string|nil | ||
function M.escape_special_chars(path) | ||
if path == nil then | ||
return path | ||
end | ||
return M.is_windows and path:gsub("\\", "/") or path | ||
return M.is_windows and escape_special_char_for_windows(path) or path |
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, this one definitely should be behind the windows feature flag.
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 this fix! This all looks reasonable and I can see how you have tested comprehensively.
The is_windows
feature flag only applies to powershell, hence you do not need to test WSL.
The nvim-tree developers don't have access to nor expertise with windows, if there is an issue we expect you to resolve it.
- All windows fixes must go behind the feature flags
utils.is_windows
etc. The existing codepaths for non-windows must remain unchanged.
@@ -370,36 +370,35 @@ end | |||
---@param mode string | |||
---@param filename string | |||
function M.fn(mode, filename) | |||
local fname = utils.escape_special_chars(filename) |
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 is a change in behaviour that will affect linux and macos users.
Please put this behind the windows feature flag, to ensure that it only applies to windows users.
Something like
local fname
if utils.is_windows then
fname = filename
else
fname = utils.escape_special_chars(filename)
end
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.
Hi @alex-courtis , change of this line is caused by the revert of previous fix. I think there wasn't such line at the begining.
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.
Please accept my apologies, I did not Seek First To Understand.
git diff bd4881660bf0ddfa6acb21259f856ba3dcb26a93 lua/nvim-tree/actions/node/open-file.lua
shows that the change #2903 has been completely reverted.
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.
Yes, I reverted all changes of #2903 .
In #2903 util.escape_special_chats
is called here and impact all file names below, which are not correct. (my tests failed)
Now and before #2903 utils.escape_special_chars
is called in the open_in_new_window
function (line 334 and 336), so I think I'm just following the logic before #2903 . And the is_windows flag is already in the utils.escape_special_chars
function, so not added outside utils.escape_special_chars
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, just the one windows feature flag check needed.
Alternative idea:
I was able to cleanly git revert 45a93d99794fff3064141d5b3a50db98ce352697
on master
You could instead do that on a new branch and apply your fixes on top.
That would result in cleaner history and a simpler PR.
Your choice.
@@ -370,36 +370,35 @@ end | |||
---@param mode string | |||
---@param filename string | |||
function M.fn(mode, filename) | |||
local fname = utils.escape_special_chars(filename) |
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.
Please accept my apologies, I did not Seek First To Understand.
git diff bd4881660bf0ddfa6acb21259f856ba3dcb26a93 lua/nvim-tree/actions/node/open-file.lua
shows that the change #2903 has been completely reverted.
end | ||
|
||
local _, r = norm_path:find(M.path_add_trailing(relative_to), 1, true) | ||
local p = norm_path |
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 path is executed for all OS, which may cause issues for such paths. Please execute only when is_windows
This injected error is definitely thrown on linux, showing that the code path is executed:
--- Check if there are parentheses before brackets, it causes problems for windows.
--- Refer to issue #2862 and #2961 for more details.
local function has_parentheses_and_brackets(path)
error("has_parentheses_and_brackets")
E5108: Error executing lua: ...d/site/pack/packer/start/ljie-PI/lua/nvim-tree/utils.lua:65: has_parentheses_and_brackets called
stack traceback:
[C]: in function 'error'
...d/site/pack/packer/start/ljie-PI/lua/nvim-tree/utils.lua:65: in function 'has_parentheses_and_brackets'
...d/site/pack/packer/start/ljie-PI/lua/nvim-tree/utils.lua:84: in function 'path_relative'
.../packer/start/ljie-PI/lua/nvim-tree/explorer/filters.lua:161: in function 'custom'
.../packer/start/ljie-PI/lua/nvim-tree/explorer/filters.lua:247: in function 'should_filter_as_reason'
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.
Added flag on line 84, so that norm_path will keep unchanged for non-windows OS.
Thank you
I'll get to this review on the weekend.
…On Mon, 21 Oct 2024, 18:34 Jie Liu, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In lua/nvim-tree/actions/node/open-file.lua
<#2962 (comment)>
:
> @@ -370,36 +370,35 @@ end
***@***.*** mode string
***@***.*** filename string
function M.fn(mode, filename)
- local fname = utils.escape_special_chars(filename)
Yes, I reverted all changes of #2903
<#2903> .
In #2903 <#2903>
util.escape_special_chats is called here and impact all file names below,
which are not correct. (my tests failed)
Now and before #2903
<#2903>
utils.escape_special_chars is called in the open_in_new_window function
(line 334 and 336), so I think I'm just following the logic before #2903
<#2903> . And the
is_windows flag is already in the utils.escape_special_chars function, so
not added outside utils.escape_special_chars
—
Reply to this email directly, view it on GitHub
<#2962 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALPQYQZ23BHI6M3FTF6BETZ4SVABAVCNFSM6AAAAABQHGGFVWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGOBRGE3TKMZWGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
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 your contribution!
Description
With this change (45a93d9#diff-eeb21711fceb0abba1450bd1adcbecc4fd90cf8ce4d5d7a8233f886c1bebd41fR375), I found it doesn't work well on Windows for 2 cases:
<cmd>lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})<cr> Neovim version
This PR is to revert the change and fix the issue #2961 and #2862