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
BUG: Can not open file insde App router with parentheses in its name. (Windows only) #1448
Comments
What is your neo-tree version? |
I don't think this is just parenthisis that is hurting you, notice that the entire path just falls over when it hits I haven't looked at the path escaping code in quite a while, I know it has morphed since I last touched it. It likely needs a bit more robustness to handle some of that weirdness |
I'm using the latest one 3.25 |
I found that I have same issue with this #889 |
Pinging @bwpge |
Ah Windows paths, the gift that keeps on giving 😂 @pysan3 I will take a look in the morning |
For anyone who wants to take a look in the meantime, my best initial guess is we'll probably just have to add braces to this escape logic (totally guessing though): neo-tree.nvim/lua/neo-tree/utils/init.lua Line 1058 in 25bfdbe
|
According to my comment #1353 (comment) I haven't been able to test so I might be completely wrong and forgive me I can't do anything until this weekends at the earliest :'( |
Reproduced the issue on my machine, looks like somewhere the parenthesis is not getting escaped (trying to open
Using the following test directory:
Edit: What I find odd though is the
As a funny side note, nice to know that even established tools like |
After doing some testing, it seems specifically the Test files:
I tried using 3 backslashes to open those files that errored and that actually worked, e.g., Just to restate, this seems to be a really specific Windows path problem with Neovim (not Neo-tree) that doesn't follow any of the other established rules about escaping, since I can't even manually open those types of paths without using a triple backslash (or using a |
Thank you so much for your deep dive @bwpge ! With my pathlib.nvim I force all path separators to be forward regardless of the OS when passing to a vim command (eg https://github.com/pysan3/pathlib.nvim/blob/main/lua/pathlib/base.lua#L1209-L1220 Do you think we should rather take this route instead? This won't raise any errors with escaping. |
The I know it's not Neo-tree's responsibility to make every other plugin in Neovim happy, but it introduces a really subtle change that is really difficult to pinpoint for users. Essentially, a lot of plugins do their own path parsing and may rely on the platform separator (e.g., Again, not really a Neo-tree problem per se, but it breaks other popular plugins. I've also run into some weird buffer behavior with LSP refactors like renaming a symbol, where it opens a buffer with the same name but different path separators. |
On the bright side, this is what I'm testing now and seems to be working for weird paths, including something like M.escape_path_for_cmd = function(path)
local escaped_path = vim.fn.fnameescape(path)
if M.is_windows then
local evil = "[%(%)%^&;`]"
escaped_path = escaped_path:gsub("\\" .. evil, "\\%1")
escaped_path = escaped_path:gsub("(" .. evil .. ")\\\\(" .. evil .. ")", "%1\\\\\\%2")
-- special case for #1448
escaped_path = escaped_path:gsub("%]\\\\%(", "]\\\\\\(")
vim.notify("DEBUG: using escaped path `" .. escaped_path .. "`")
end
return escaped_path
end
|
Just wanted to check in, haven't forgotten about this issue just had a crazy schedule this week. Hope to get a PR sent in tonight or tomorrow night. |
From some more testing, I've come to the conclusion that a square bracket or backtick in the path makes other problematic punctuation (the ones we discovered like I'm using the following script to verify logic: local punc = { "()", "[]", "^", "&", ";", "`" }
-- testing implementation for this function
local function escape_path_for_cmd(path)
local escaped_path = vim.fn.fnameescape(path)
if true then
local need_extra_esc = path:find("[%[%]`]")
local esc = need_extra_esc and "\\\\" or "\\"
escaped_path = escaped_path:gsub("\\[%(%)%^&;]", esc .. "%1")
-- backticks get escaped by fnameescape and always need an extra
-- separator if they are the first character in a path segment
escaped_path = escaped_path:gsub("\\\\`", "\\%1")
end
return escaped_path
end
-- makes a value like `[foo]` from part='foo' and p='[]'
local function make_part(part, p)
local open = p:sub(1, 1)
local close = p:sub(2, 2)
if close == "" then
close = open
end
return (open .. part .. close)
end
-- create nested directories with leading/trailing punctuation
local dirs = {}
for _, p1 in ipairs(punc) do
for _, p2 in ipairs(punc) do
local part1 = make_part("foo", p1)
local part2 = make_part("bar", p2)
local path = string.format(".\\tests\\%s\\%s", part1, part2)
vim.fn.mkdir(path, "p")
table.insert(dirs, path)
end
end
-- try to write files with weird path
for _, d in ipairs(dirs) do
local p = escape_path_for_cmd(d .. "\\bar.txt")
local ok, err = pcall(vim.cmd, "silent w " .. p)
if not ok then
print("fail:", p, "->", err)
else
print("wrote:", p)
end
end This solution above solves the problem for all paths tested:
I have some things to take care of today but later I'm going to test all the same punctuation above on the beginning filename (I found that this creates some additional problems, so I want to test that separately). |
Did you check docs and existing issues?
Neovim Version (nvim -v)
0.9.5
Operating System / Version
Win 10
Describe the Bug
Can not open file insde App router with parentheses in its name. (Windows only)
Screenshots, Traceback
Steps to Reproduce
Expected Behavior
Can open the file
Your Configuration
The text was updated successfully, but these errors were encountered: