Skip to content

Commit b848fd8

Browse files
authored
Merge pull request #16858 from JuliaLang/tk/urlbackslash
Replace '\\' with '/' for Windows filenames in Base.url
2 parents dab5c8d + 4b21f43 commit b848fd8

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

base/methodshow.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function url(m::Method)
174174
file = string(m.file)
175175
line = m.line
176176
line <= 0 || ismatch(r"In\[[0-9]+\]", file) && return ""
177+
is_windows() && (file = replace(file, '\\', '/'))
177178
if inbase(M)
178179
if isempty(Base.GIT_VERSION_INFO.commit)
179180
# this url will only work if we're on a tagged release
@@ -190,7 +191,7 @@ function url(m::Method)
190191
u = match(LibGit2.GITHUB_REGEX,u).captures[1]
191192
commit = string(LibGit2.head_oid(repo))
192193
root = LibGit2.path(repo)
193-
if startswith(file, root)
194+
if startswith(file, root) || startswith(realpath(file), root)
194195
"https://github.com/$u/tree/$commit/"*file[length(root)+1:end]*"#L$line"
195196
else
196197
fileurl(file)

test/pkg.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ temp_pkg_dir() do
185185
Pkg.pin("Example", v"0.4.0")
186186
@test Pkg.update() == nothing
187187
Pkg.installed()["Example"] == v"0.4.0"
188+
189+
# bug identified in #16850, Base.url \ vs / for non-Base methods
190+
include(Pkg.dir("Example","src","Example.jl"))
191+
meth = first(methods(Example.domath))
192+
fname = string(meth.file)
193+
@test ('\\' in fname) == is_windows()
194+
@test startswith(Base.url(meth), "https://github.com/JuliaLang/Example.jl/tree")
188195
end
189196

190197
# add a directory that is not a git repository

test/reflection.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,50 @@ fLargeTable() = 4
451451
# issue #15280
452452
function f15280(x) end
453453
@test functionloc(f15280)[2] > 0
454+
455+
# bug found in #16850, Base.url with backslashes on Windows
456+
function module_depth(from::Module, to::Module)
457+
if from === to
458+
return 0
459+
else
460+
return 1 + module_depth(from, module_parent(to))
461+
end
462+
end
463+
function has_backslashes(mod::Module)
464+
for n in names(mod, true, true)
465+
isdefined(mod, n) || continue
466+
f = getfield(mod, n)
467+
if isa(f, Module) && module_depth(Main, f) <= module_depth(Main, mod)
468+
continue
469+
end
470+
h = has_backslashes(f)
471+
isnull(h) || return h
472+
end
473+
return Nullable{Method}()
474+
end
475+
function has_backslashes(f::Function)
476+
for m in methods(f)
477+
h = has_backslashes(m)
478+
isnull(h) || return h
479+
end
480+
return Nullable{Method}()
481+
end
482+
function has_backslashes(meth::Method)
483+
if '\\' in string(meth.file)
484+
return Nullable{Method}(meth)
485+
else
486+
return Nullable{Method}()
487+
end
488+
end
489+
has_backslashes(x) = Nullable{Method}()
490+
h16850 = has_backslashes(Base)
491+
if is_windows()
492+
if isnull(h16850)
493+
warn("No methods found in Base with backslashes in file name, ",
494+
"skipping test for Base.url")
495+
else
496+
@test !('\\' in Base.url(get(h16850)))
497+
end
498+
else
499+
@test isnull(h16850)
500+
end

0 commit comments

Comments
 (0)