From 0bef3b911cc262a007fb4412d864c1832d1268ad Mon Sep 17 00:00:00 2001 From: Gustav Eikaas <46537983+GustavEikaas@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:40:05 +0100 Subject: fix(vim.fs): joinpath() does not normalize slashes on Windows #31782 --- runtime/lua/vim/fs.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua index f2cd210cac..1b774d5cab 100644 --- a/runtime/lua/vim/fs.lua +++ b/runtime/lua/vim/fs.lua @@ -105,14 +105,19 @@ function M.basename(file) return file:match('/$') and '' or (file:match('[^/]*$')) end ---- Concatenate directories and/or file paths into a single path with normalization ---- (e.g., `"foo/"` and `"bar"` get joined to `"foo/bar"`) +--- Concatenates partial paths into one path. Slashes are normalized (redundant slashes are removed, and on Windows backslashes are replaced with forward-slashes) +--- (e.g., `"foo/"` and `"/bar"` get joined to `"foo/bar"`) +--- (windows: e.g `"a\foo\"` and `"\bar"` are joined to `"a/foo/bar"`) --- ---@since 12 ---@param ... string ---@return string function M.joinpath(...) - return (table.concat({ ... }, '/'):gsub('//+', '/')) + local path = table.concat({ ... }, '/') + if iswin then + path = path:gsub('\\', '/') + end + return (path:gsub('//+', '/')) end ---@alias Iterator fun(): string?, string? -- cgit