From 69da35493ce078cf0770d655d120267a189c514c Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:59:26 -0300 Subject: [PATCH] Fix julia#55850 by using safe_realpath instead of abspath in projname (#4025) (#4027) --- src/REPLMode/REPLMode.jl | 4 ++-- test/repl.jl | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 09c3ba47de..f6311324f7 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -10,7 +10,7 @@ import REPL: TerminalMenus import ..casesensitive_isdir, ..OFFLINE_MODE, ..linewrap, ..pathrepr using ..Types, ..Operations, ..API, ..Registry, ..Resolve -import ..stdout_f, ..stderr_f +import ..stdout_f, ..stderr_f, ..safe_realpath const TEST_MODE = Ref{Bool}(false) const PRINTED_REPL_WARNING = Ref{Bool}(false) @@ -497,7 +497,7 @@ function projname(project_file::String) end for depot in Base.DEPOT_PATH envdir = joinpath(depot, "environments") - if startswith(abspath(project_file), abspath(envdir)) + if startswith(safe_realpath(project_file), safe_realpath(envdir)) return "@" * name end end diff --git a/test/repl.jl b/test/repl.jl index ca86943614..06f647171b 100644 --- a/test/repl.jl +++ b/test/repl.jl @@ -726,4 +726,15 @@ end end end +@testset "JuliaLang/julia #55850" begin + tmp_55850 = mktempdir() + tmp_sym_link = joinpath(tmp_55850, "sym") + symlink(tmp_55850, tmp_sym_link; dir_target=true) + # DEPOT_PATH must stay only the temp directory otherwise the bug is hidden + withenv("JULIA_DEPOT_PATH" => tmp_sym_link, "JULIA_LOAD_PATH" => nothing) do + prompt = readchomp(`$(Base.julia_cmd()[1]) --project=$(dirname(@__DIR__)) --startup-file=no -e "using Pkg: Pkg, REPLMode; Pkg.activate(io=devnull); print(REPLMode.promptf())"`) + @test prompt == "(@v$(VERSION.major).$(VERSION.minor)) pkg> " + end +end + end # module