diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua index 0a4247d543..ab58202a4c 100644 --- a/runtime/lua/vim/fs.lua +++ b/runtime/lua/vim/fs.lua @@ -344,7 +344,11 @@ function M.normalize(path, opts) path = path:gsub('%$([%w_]+)', vim.loop.os_getenv) end - return (path:gsub('\\', '/'):gsub('/+', '/'):gsub('(.)/$', '%1')) + path = path:gsub('\\', '/'):gsub('/+', '/') + if iswin and path:match('^%w:/$') then + return path + end + return (path:gsub('(.)/$', '%1')) end return M diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 9b7499422d..298c2fdfe7 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -290,5 +290,10 @@ describe('vim.fs', function() return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') ]], xdg_config_home)) end) + if is_os('win') then + it('Last slash is not truncated from root drive', function() + eq('C:/', exec_lua [[ return vim.fs.normalize('C:/') ]]) + end) + end end) end)