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

drag-n-drop to open file that has "()" in its PATH #1983

Closed
xarthurx opened this issue Aug 16, 2023 · 6 comments · Fixed by #2056
Closed

drag-n-drop to open file that has "()" in its PATH #1983

xarthurx opened this issue Aug 16, 2023 · 6 comments · Fixed by #2056
Labels
bug Something isn't working

Comments

@xarthurx
Copy link

Describe the bug

On Windows, I cannot drag-n-drop files with paths like this:

C:/(this-path)/file.md

Windows native notepad can open the file successfully.

This is similar but different to the issue: #1608

To Reproduce
Steps to reproduce the behavior:

  1. Create a folder structure containing "()" in the folder name
  2. Create a file in the folder
  3. Drag-n-drop to open that file from neovide
  4. See error

Expected behavior
The file can be opened successfully

Desktop (please complete the following information):

  • OS: Windows
  • Neovide Version: 0.11.0
  • Neovim Version 0.9.1

Please run neovide --log and paste the contents of the .log file created in the current directory here:
nothing

@xarthurx xarthurx added the bug Something isn't working label Aug 16, 2023
@xarthurx
Copy link
Author

If I drag-n-drop routes\(index).tsx the file that is actually opened is: routes(index).tsx
image

@jonvaldes
Copy link
Collaborator

I confirm I can see the same issue. However, I believe this might be an underlying nvim issue. Let me explain.

I created a file with this path C:\(moo)\moo.txt.

When drag&dropped onto neovide, the file path gets passed in as "C:\(moo)\moo.txt", which is then put into a FileDrop event and executed as an nvim command with this line:

                nvim.command(format!("e {path}").as_str()).await.ok();

That format! call produces this string: e C:\(moo)\moo.txt

This command does, indeed, not load the correct file, and instead creates a new file with a different path.

However, when executing that command manually in standalone nvim, I get the same issue.

For example, in my test nvim ended up creating a file in C:\CODE\neovide\C:(moo)\moo.txt, because my cwd was C:\CODE\neovide\.

IMO this should go to the nvim team, I don't think neovide is at fault here.

@fredizzimo
Copy link
Member

I think @xarthurx already tried to report it there neovim/neovim#24542, but it got closed.

But reading that I'm not sure if they understood the issue correctly. completeslash can probably solve that very specific issue, but not the underlying cause.

@xarthurx
Copy link
Author

Yes, they say they can do nothing about it.
I think if we can replace \ with /, which is the Windows path separator, then the issue should be resolved.
The nvim-tree plugin fix this PATH issue recently.

@jonvaldes
Copy link
Collaborator

Yes, manually using e C:/(moo)/moo.txt instead works correctly in both nvim and neovide.

Doing a wholesale file_path.replace('\\', '/') is likely fine on Windows, but I'm unsure whether it could have some unintended consequences on other platforms 🤔

@ZyX-II
Copy link
Contributor

ZyX-II commented Sep 28, 2023

Doing a wholesale file_path.replace('\\', '/') is likely fine on Windows, but I'm unsure whether it could have some unintended consequences on other platforms 🤔

\ is perfectly valid character to have in path on *nix platforms. Or, more specifically, you generally should expect path to contain anything that is not a zero byte. For instance, I am on Windows and have a number of files with names like example#sharing.pini which I cannot open by dragging and dropping them into Neovide because unescaped # expands to some file name (alternate buffer name? Never used that). For this reason

nvim.command(format!("e {path}").as_str()).await.ok();

is not a correct way to open file on any system, special characters must be escaped. (Also theoretically you can run arbitrary code by having files with names like | call system("foo") (not on Windows).)

ZyX-II pushed a commit to ZyX-II/neovide that referenced this issue Sep 28, 2023
MultisampledNight added a commit that referenced this issue Oct 14, 2023
)

* Run :edit command with nvim_cmd to escape special characters

Fixes #1983

* Use a bit less verbose .cmd() function

* codestyle: use .into() for Value conversion instead

* codestyle: calm rustfmt

---------

Co-authored-by: ZyX <napav.spels@yandex.ru>
Co-authored-by: MultisampledNight <contact@multisamplednight.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants