Merge pull request #24384 from neovim/backport-23753-to-release-0.9

[Backport release-0.9] fix(fs.lua): normalize slash truncation
This commit is contained in:
zeertzjq
2023-07-18 14:46:07 +08:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@@ -344,7 +344,11 @@ function M.normalize(path, opts)
path = path:gsub('%$([%w_]+)', vim.loop.os_getenv) path = path:gsub('%$([%w_]+)', vim.loop.os_getenv)
end 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 end
return M return M

View File

@@ -290,5 +290,10 @@ describe('vim.fs', function()
return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') return vim.fs.normalize('$XDG_CONFIG_HOME/nvim')
]], xdg_config_home)) ]], xdg_config_home))
end) 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)
end) end)