Skip to content

Commit

Permalink
Fix #38491: fix an abspath() edge case on Windows (#38981)
Browse files Browse the repository at this point in the history
* Fix #38491: fix an abspath() edge case on Windows

* Update base/path.jl

Co-authored-by: Jameson Nash <vtjnash@gmail.com>

* Update base/path.jl

* Update test/path.jl

Co-authored-by: Jameson Nash <vtjnash@gmail.com>

Co-authored-by: Mustafa M <mus-m@outlook.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
(cherry picked from commit f023677)
  • Loading branch information
belamenso authored and KristofferC committed Apr 4, 2021
1 parent 6a93c03 commit f6787a9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,19 @@ normpath(a::AbstractString, b::AbstractString...) = normpath(joinpath(a,b...))
Convert a path to an absolute path by adding the current directory if necessary.
Also normalizes the path as in [`normpath`](@ref).
"""
abspath(a::String) = normpath(isabspath(a) ? a : joinpath(pwd(),a))
function abspath(a::String)::String
if !isabspath(a)
cwd = pwd()
a_drive, a_nodrive = splitdrive(a)
if a_drive != "" && lowercase(splitdrive(cwd)[1]) != lowercase(a_drive)
cwd = a_drive * path_separator
a = joinpath(cwd, a_nodrive)
else
a = joinpath(cwd, a)
end
end
return normpath(a)
end

"""
abspath(path::AbstractString, paths::AbstractString...) -> String
Expand Down
17 changes: 17 additions & 0 deletions test/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
@test isabspath(S(homedir()))
@test !isabspath(S("foo"))
end
if Sys.iswindows()
@testset "issue #38491" begin
pwd_drive = uppercase(splitdrive(pwd())[1])
drive = (pwd_drive == "X:") ? "Y:" : "X:"
@test abspath("$(lowercase(drive))a\\b\\c") == "$(lowercase(drive))\\a\\b\\c"
@test abspath("$(uppercase(drive))a\\b\\c") == "$(uppercase(drive))\\a\\b\\c"
@test abspath("$(lowercase(drive))a") == "$(lowercase(drive))\\a"
@test abspath("$(uppercase(drive))a") == "$(uppercase(drive))\\a"
@test abspath(lowercase(drive)) == "$(lowercase(drive))\\"
@test abspath(uppercase(drive)) == "$(uppercase(drive))\\"

@test lowercase(abspath("$(pwd_drive)a\\b\\c")) == lowercase(joinpath(pwd(), "a\\b\\c"))
@test lowercase(abspath("$(pwd_drive)a")) == lowercase(joinpath(pwd(), "a"))
@test lowercase(abspath(lowercase(pwd_drive))) == lowercase("$(pwd())\\")
@test lowercase(abspath(uppercase(pwd_drive))) == lowercase("$(pwd())\\")
end
end
@test basename(S("foo$(sep)bar")) == "bar"
@test dirname(S("foo$(sep)bar")) == "foo"

Expand Down

0 comments on commit f6787a9

Please sign in to comment.