Skip to content

Commit 9c3239b

Browse files
authored
fix: Path:absolute on windows returns double disk name part if path contains .. (#324)
* fix: return boolean from Path:is_absolute instead of string on Windows * fix: Path:absolute double disk names on Windows
1 parent 54b2e3d commit 9c3239b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lua/plenary/path.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ end
7878

7979
local is_absolute = function(filename, sep)
8080
if sep == "\\" then
81-
return string.match(filename, "^[%a]:\\.*$")
81+
return string.match(filename, "^[%a]:\\.*$") ~= nil
8282
end
8383
return string.sub(filename, 1, 1) == sep
8484
end
@@ -99,8 +99,17 @@ local function _normalize_path(filename, cwd)
9999
local has = string.find(filename, path.sep .. "..", 1, true) or string.find(filename, ".." .. path.sep, 1, true)
100100

101101
if has then
102-
local parts = _split_by_separator(filename)
102+
local is_abs = is_absolute(filename, path.sep)
103+
local split_without_disk_name = function(filename_local)
104+
local parts = _split_by_separator(filename_local)
105+
-- Remove disk name part on Windows
106+
if path.sep == "\\" and is_abs then
107+
table.remove(parts, 1)
108+
end
109+
return parts
110+
end
103111

112+
local parts = split_without_disk_name(filename)
104113
local idx = 1
105114
local initial_up_count = 0
106115

@@ -121,7 +130,7 @@ local function _normalize_path(filename, cwd)
121130
until idx > #parts
122131

123132
local prefix = ""
124-
if is_absolute(filename, path.sep) or #_split_by_separator(cwd) == initial_up_count then
133+
if is_abs or #split_without_disk_name(cwd) == initial_up_count then
125134
prefix = path.root(filename)
126135
end
127136

0 commit comments

Comments
 (0)