Skip to content

Commit b19202b

Browse files
committed
FIX: Correctly handle Windows paths that do not start with a drive letter
On Windows, an absolute path should start with a drive letter, or UNC notation. xolox#misc#path#split() doesn't consider drive-local filespecs (e.g. \Windows\system32); it needs a check for a leading path separator like the Unix branch. xolox#misc#path#absolute() doesn't convert a drive-local filespec into a full absolute one (e.g. C:\Windows\system32); it needs a check for those and prepend the current drive letter then.
1 parent e3f28a7 commit b19202b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

autoload/xolox/misc/path.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ function! xolox#misc#path#split(path) " {{{1
7272
" UNC pathname.
7373
return split(a:path, '\%>2c[\/]\+')
7474
else
75+
let absolute = (a:path =~ '^[\/]')
7576
" If it's not a UNC path we can simply split on slashes & backslashes.
76-
return split(a:path, '[\/]\+')
77+
let segments = split(a:path, '[\/]\+')
78+
return absolute ? insert(segments, a:path[0]) : segments
7779
endif
7880
else
7981
" Everything else is treated as UNIX.
@@ -135,6 +137,8 @@ function! xolox#misc#path#absolute(path) " {{{1
135137
" Also normalize the two leading "directory separators" (I'm not
136138
" sure what else to call them :-) in Windows UNC pathnames.
137139
let parts[0] = repeat(xolox#misc#path#directory_separator(), 2) . parts[0][2:]
140+
elseif s:windows_compatible && parts[0] =~ '^[\/]$'
141+
let parts[0] = matchstr(getcwd(), '^\a:')
138142
endif
139143
return xolox#misc#path#join(parts)
140144
endif

0 commit comments

Comments
 (0)