Skip to content

fix(#2352): windows: escape special filename characters on edit #2374

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

Merged
merged 6 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ local function open_in_new_window(filename, mode)
end

local fname = vim.fn.fnameescape(filename)
fname = utils.escape_special_chars(fname)

local cmd
if create_new_window then
Expand Down
10 changes: 10 additions & 0 deletions lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ function M.canonical_path(path)
return path
end

-- Escapes special characters in string if windows else returns unmodified string.
-- @param path string
-- @return path
function M.escape_special_chars(path)
if path == nil then
return path
end
return M.is_windows and path:gsub("%(", "\\("):gsub("%)", "\\)") or path
end

-- Create empty sub-tables if not present
-- @param tbl to create empty inside of
-- @param path dot separated string of sub-tables
Expand Down