Skip to content

Commit 7c4c7e4

Browse files
davisthedevDavis Sandersalex-courtis
authored
fix(#2352): windows: escape special filename characters on edit (#2374)
* Fix escape special characters on windows fixes #2362 * use utils for windows check * Add function to escape special chars on windows * Change escape string function to use and/or * Add nil check in escape special chars function --------- Co-authored-by: Davis Sanders <dsanders@smartlink.city> Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent 4e36850 commit 7c4c7e4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ local function open_in_new_window(filename, mode)
270270
end
271271

272272
local fname = vim.fn.fnameescape(filename)
273+
fname = utils.escape_special_chars(fname)
273274

274275
local cmd
275276
if create_new_window then

lua/nvim-tree/utils.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ function M.canonical_path(path)
210210
return path
211211
end
212212

213+
-- Escapes special characters in string if windows else returns unmodified string.
214+
-- @param path string
215+
-- @return path
216+
function M.escape_special_chars(path)
217+
if path == nil then
218+
return path
219+
end
220+
return M.is_windows and path:gsub("%(", "\\("):gsub("%)", "\\)") or path
221+
end
222+
213223
-- Create empty sub-tables if not present
214224
-- @param tbl to create empty inside of
215225
-- @param path dot separated string of sub-tables

0 commit comments

Comments
 (0)