Skip to content

Commit 58754dd

Browse files
committed
Fix relative path w/ drive ("C:a"->["C:a"]), and empty path (""->[""]).
1 parent 1ea9017 commit 58754dd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

base/path.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ julia> splitpath("/home/myuser/example.jl")
211211
```
212212
"""
213213
function splitpath(p::String)
214+
drive, p = splitdrive(p)
214215
out = String[]
216+
isempty(p) && (pushfirst!(out,p)) # "" means the current directory.
215217
while !isempty(p)
216218
dir, base = splitdir(p)
217219
dir == p && (pushfirst!(out, dir); break) # Reached root node.
@@ -220,6 +222,9 @@ function splitpath(p::String)
220222
end
221223
p = dir
222224
end
225+
if !isempty(drive) # Tack the drive back on to the first element.
226+
out[1] = drive*out[1] # Note that length(out) is always >= 1.
227+
end
223228
return out
224229
end
225230

test/path.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
@testset "splitpath" begin
8989
@test splitpath(joinpath("a","b","c")) == ["a", "b", "c"]
90-
@test splitpath("") == []
90+
@test splitpath("") == [""]
9191

9292
@test splitpath(joinpath("cats are", "gr8t")) == ["cats are", "gr8t"]
9393
@test splitpath(joinpath(" ", " ")) == [" ", " "]
@@ -106,13 +106,14 @@
106106
@test splitpath("C:\\\\") == ["C:\\"]
107107
@test splitpath("J:\\") == ["J:\\"]
108108
@test splitpath("C:") == ["C:"]
109-
@test splitpath("C:a") == ["C:", "a"]
110-
@test splitpath("C:a\\b") == ["C:", "a", "b"]
109+
@test splitpath("C:a") == ["C:a"]
110+
@test splitpath("C:a\\b") == ["C:a", "b"]
111111

112112
@test splitpath("a\\") == ["a"]
113113
@test splitpath("a\\\\b\\\\") == ["a","b"]
114114
@test splitpath("a.dir\\b.txt") == ["a.dir", "b.txt"]
115115
@test splitpath("\\a\\b\\") == ["\\", "a","b"]
116+
@test splitpath("\\\\a\\b") == ["\\", "a","b"]
116117

117118
@test splitpath("/a/b\\c/d\\\\e") == ["/", "a", "b", "c", "d", "e"]
118119
@test splitpath("/\\/\\") == ["/"]

0 commit comments

Comments
 (0)