mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
[Backport release-0.9] fix(fs): make normalize()
work with '/' path (#24060)
fix(fs): make `normalize()` work with '/' path
Problem: Current implementation of "remove trailing /" doesn't
account for the case of literal '/' as path.
Solution: Remove trailing / only if it preceded by something else.
(cherry picked from commit 80ff66118a
)
Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
This commit is contained in:
![41898282+github-actions[bot]@users.noreply.github.com](/assets/img/avatar_default.png)
committed by
GitHub

parent
d9a76056bb
commit
b9a513ae11
@@ -344,9 +344,7 @@ function M.normalize(path, opts)
|
|||||||
path = path:gsub('%$([%w_]+)', vim.loop.os_getenv)
|
path = path:gsub('%$([%w_]+)', vim.loop.os_getenv)
|
||||||
end
|
end
|
||||||
|
|
||||||
path = path:gsub('\\', '/'):gsub('/+', '/')
|
return (path:gsub('\\', '/'):gsub('/+', '/'):gsub('(.)/$', '%1'))
|
||||||
|
|
||||||
return path:sub(-1) == '/' and path:sub(1, -2) or path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@@ -270,6 +270,12 @@ describe('vim.fs', function()
|
|||||||
it('works with backward slashes', function()
|
it('works with backward slashes', function()
|
||||||
eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]])
|
eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]])
|
||||||
end)
|
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()
|
it('works with ~', function()
|
||||||
eq( exec_lua([[
|
eq( exec_lua([[
|
||||||
local home = ...
|
local home = ...
|
||||||
|
Reference in New Issue
Block a user