aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/fs.lua4
-rw-r--r--test/functional/lua/fs_spec.lua6
2 files changed, 7 insertions, 3 deletions
diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua
index c89147dbd2..cdb314fa3d 100644
--- a/runtime/lua/vim/fs.lua
+++ b/runtime/lua/vim/fs.lua
@@ -348,9 +348,7 @@ function M.normalize(path, opts)
path = path:gsub('%$([%w_]+)', vim.uv.os_getenv)
end
- path = path:gsub('\\', '/'):gsub('/+', '/')
-
- return path:sub(-1) == '/' and path:sub(1, -2) or path
+ return (path:gsub('\\', '/'):gsub('/+', '/'):gsub('(.)/$', '%1'))
end
return M
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index aae0ed91a7..c1091cff60 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -281,6 +281,12 @@ describe('vim.fs', function()
it('works with backward slashes', function()
eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]])
end)
+ it('removes trailing /', function()
+ eq('/home/user', exec_lua [[ return vim.fs.normalize('/home/user/') ]])
+ end)
+ it('works with /', function()
+ eq('/', exec_lua [[ return vim.fs.normalize('/') ]])
+ end)
it('works with ~', function()
eq( exec_lua([[
local home = ...