From 7c4c7e4e984db6ec012b0e3df11791a118d638aa Mon Sep 17 00:00:00 2001 From: davisthedev <88169904+davisthedev@users.noreply.github.com> Date: Sat, 19 Aug 2023 23:27:33 -0400 Subject: [PATCH] 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 Co-authored-by: Alexander Courtis --- lua/nvim-tree/actions/node/open-file.lua | 1 + lua/nvim-tree/utils.lua | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 35ec6b66..0add9560 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -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 diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index 78d7853b..386472ea 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -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