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

Update fs_actions.lua fixes #1399 #1400

Merged
merged 3 commits into from Mar 15, 2024
Merged

Conversation

WillEhrendreich
Copy link
Contributor

No description provided.

@@ -496,7 +496,7 @@ M.delete_node = function(path, callback, noconfirm)
-- first try using native system commands, which are recursive
local success = false
if utils.is_windows then
local result = vim.fn.system({ "cmd.exe", "/c", "rmdir", "/s", "/q", path })
local result = vim.fn.system({ "cmd.exe", "/c", "rmdir", "/s", "/q", '"', path, '"' })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the bug and thanks for fixing, but I think there may be a better way to go about quoting. Isn't there a vim api to shellescape paths? My concern is that there may still be other file path issues we are not handling here and we should take this opportunity to address them all.

@pysan3 what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang it. I explicitly said we need to add check for <Space> on top of the punctuations but then completely forgot about that when reviewing the PR: #1388

Copy link
Collaborator

@pysan3 pysan3 Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bwpge Pinging you again :)

We needed " " (check for space) at the end of the list in #1388. Right?

No this is an actual issue not related to the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's that cmd.exe /C treats all following arguments as single string and runs that command so it forgets that path is one argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll definitely take a look when I get some time tonight.

To address @cseickel's point, the user can change their shell/shell escaping options (example :h shell-powershell), so if we're deliberately using cmd for Windows (which is a good approach for compatibility like if a user can't use powershell on corporate machines) we'll probably have to escape that ourselves.

And of course cmd plays by its own made up rules when it comes to escapes and quoting...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be less pain to not run cmd.exe when path contains space or puncts and fallback to recursively vim.loop.fs_rmdir?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using vim.fn.shellescape(path) might be better than '"' .. path .. '"' to say the least.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some amount of testing, I think shellescape does the job. I could not find any edge cases.

@WillEhrendreich Could you change your fix to use vim.fn.shellescape(path) instead? It would be nice if you could test your issue with this change.

@bwpge May I get a confirmation from you as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @cseickel

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pysan3 just a note, vim.fn.shellescape relies on the user's shellslash option (only applies to Windows). While I highly doubt in general people will mess with this setting, and it is off by default, it can create the following (difficult to troubleshoot) issue with a path like foo/bar's (note the use of single vs double quotes):

  • With shellslash false: "foo/bar's" -> valid
  • With shellslash true: 'foo/bar'\''s' -> invalid

Obviously is a bit contrived, and is definitely better than what we had before, but is something to be aware of.

Copy link
Contributor

@cseickel cseickel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks everyone for helping out with this.
@WillEhrendreich @pysan3 @bwpge

@cseickel cseickel merged commit 00b46a1 into nvim-neo-tree:main Mar 15, 2024
2 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.

None yet

4 participants