diff --git a/base/path.jl b/base/path.jl index adeadf0ba7e1c..ca3c0fae6bbbb 100644 --- a/base/path.jl +++ b/base/path.jl @@ -214,13 +214,13 @@ function splitpath(p::String) out = String[] while !isempty(p) dir, base = splitdir(p) - dir == p && (push!(out, dir); break) # Reached root node. + dir == p && (pushfirst!(out, dir); break) # Reached root node. if !isempty(base) # Skip trailing '/' in basename - push!(out, base) + pushfirst!(out, base) end - p = dir; + p = dir end - return reverse!(out) + return out end joinpath(a::AbstractString) = a diff --git a/base/precompile.jl b/base/precompile.jl index 91b22d9bc9cf4..4889e1729d20e 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -122,7 +122,6 @@ precompile(Tuple{typeof(Base.Filesystem.isdir), String}) precompile(Tuple{typeof(Base.Filesystem.pwd)}) precompile(Tuple{typeof(Base.Filesystem.splitdir), String}) precompile(Tuple{typeof(Base.Filesystem.splitext), String}) -precompile(Tuple{typeof(Base.Filesystem.splitpath), String}) precompile(Tuple{typeof(Base.Meta.isexpr), Symbol, Symbol, Int64}) precompile(Tuple{typeof(Base.Meta.parse), String}) precompile(Tuple{typeof(Base.Multimedia.display), Int64}) diff --git a/test/path.jl b/test/path.jl index e222398df3af4..b5a68bc67c5f3 100644 --- a/test/path.jl +++ b/test/path.jl @@ -86,34 +86,37 @@ @test relpath(S(joinpath("foo","bar")), S("foo")) == "bar" @testset "splitpath" begin - @test ["a", "b", "c"] == splitpath(joinpath("a","b","c")) - @test [] == splitpath("") + @test splitpath(joinpath("a","b","c")) == ["a", "b", "c"] + @test splitpath("") == [] - @test ["cats are", "gr8t"] == splitpath(joinpath("cats are", "gr8t")) - @test [" ", " "] == splitpath(joinpath(" ", " ")) + @test splitpath(joinpath("cats are", "gr8t")) == ["cats are", "gr8t"] + @test splitpath(joinpath(" ", " ")) == [" ", " "] # Unix-style paths are understood by all systems. - @test ["/", "a", "b"] == splitpath("/a/b") - @test ["/"] == splitpath("/") - @test ["a"] == splitpath("a/") - @test ["a", "b"] == splitpath("a/b/") - @test ["a.dir", "b.txt"] == splitpath("a.dir/b.txt") - @test ["/"] == splitpath("///") - @test ["/", "a", "b"] == splitpath("///a///b///") + @test splitpath("/a/b") == ["/", "a", "b"] + @test splitpath("/") == ["/"] + @test splitpath("a/") == ["a"] + @test splitpath("a/b/") == ["a", "b"] + @test splitpath("a.dir/b.txt") == ["a.dir", "b.txt"] + @test splitpath("///") == ["/"] + @test splitpath("///a///b///") == ["/", "a", "b"] if Sys.iswindows() - @test ["C:\\", "a", "b", "c"] == splitpath("C:\\\\a\\b\\c") - @test ["C:\\"] == splitpath("C:\\\\") - @test ["J:\\"] == splitpath("J:\\") - @test ["C:"] == splitpath("C:") - @test ["a"] == splitpath("a\\") - @test ["a","b"] == splitpath("a\\\\b\\\\") - @test ["a.dir", "b.txt"] == splitpath("a.dir\\b.txt") - @test ["\\", "a","b"] == splitpath("\\a\\b\\") + @test splitpath("C:\\\\a\\b\\c") == ["C:\\", "a", "b", "c"] + @test splitpath("C:\\\\") == ["C:\\"] + @test splitpath("J:\\") == ["J:\\"] + @test splitpath("C:") == ["C:"] + @test splitpath("C:a") == ["C:"] + @test splitpath("C:a\\b") == ["C:"] - @test ["/", "a", "b", "c", "d", "e"] == splitpath("/a/b\\c/d\\\\e") - @test ["/"] == splitpath("/\\/\\") - @test ["\\","a","b"] == splitpath("\\/\\a/\\//b") + @test splitpath("a\\") == ["a"] + @test splitpath("a\\\\b\\\\") == ["a","b"] + @test splitpath("a.dir\\b.txt") == ["a.dir", "b.txt"] + @test splitpath("\\a\\b\\") == ["\\", "a","b"] + + @test splitpath("/a/b\\c/d\\\\e") == ["/", "a", "b", "c", "d", "e"] + @test splitpath("/\\/\\") == ["/"] + @test splitpath("\\/\\a/\\//b") == ["\\","a","b"] end end