Skip to content

Commit

Permalink
Exclude starting slash from path in URL_REGEX (JuliaLang#23574)
Browse files Browse the repository at this point in the history
Keeps URL parsing consistent between the scp-like syntax and the scheme
based parsing.
  • Loading branch information
omus committed Sep 6, 2017
1 parent f32499f commit 7bb0d53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions base/libgit2/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ const URL_REGEX = r"""
)?
(?<host>[A-Za-z0-9\-\.]+)
(?(<scheme>)
(?:\:(?<port>\d+))? # only parse port when not using scp-like syntax
# Only parse port when not using scp-like syntax
(?:\:(?<port>\d+))?
/?
|
:?
)
(?<path>
(?(<scheme>)/|(?<=:)) # scp-like syntax must be preceeded by a colon
# Require path to be preceeded by '/'. Alternatively, ':' when using scp-like syntax.
(?<=(?(<scheme>)/|:))
.*
)?
$
Expand Down
16 changes: 8 additions & 8 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ end
@test m[:password] == "pass"
@test m[:host] == "server.com"
@test m[:port] == "80"
@test m[:path] == "/org/project.git"
@test m[:path] == "org/project.git"
end

@testset "SSH URL" begin
Expand All @@ -133,7 +133,7 @@ end
@test m[:password] == "pass"
@test m[:host] == "server"
@test m[:port] == "22"
@test m[:path] == "/project.git"
@test m[:path] == "project.git"
end

@testset "SSH URL, scp-like syntax" begin
Expand Down Expand Up @@ -165,7 +165,7 @@ end
@test m[:password] === nothing
@test m[:host] == "github.com"
@test m[:port] === nothing
@test m[:path] == "/JuliaLang/Example.jl.git"
@test m[:path] == "JuliaLang/Example.jl.git"
end

@testset "SSH URL, realistic" begin
Expand Down Expand Up @@ -216,7 +216,7 @@ end
password="pass",
host="server.com",
port=80,
path="/org/project.git")
path="org/project.git")
@test url == "https://user:[email protected]:80/org/project.git"
end

Expand All @@ -227,7 +227,7 @@ end
password="pass",
host="server",
port="22",
path="/project.git")
path="project.git")
@test url == "ssh:https://user:pass@server:22/project.git"
end

Expand All @@ -244,7 +244,7 @@ end
url = LibGit2.git_url(
scheme="https",
host="github.com",
path="/JuliaLang/Example.jl.git")
path="JuliaLang/Example.jl.git")
@test url == "https://github.com/JuliaLang/Example.jl.git"
end

Expand Down Expand Up @@ -273,11 +273,11 @@ end
@test url == "[email protected]"
end

@testset "HTTP URL, path missing slash prefix" begin
@testset "HTTP URL, path includes slash prefix" begin
url = LibGit2.git_url(
scheme="http",
host="server.com",
path="path")
path="/path")
@test url == "http:https://server.com/path"
end

Expand Down

0 comments on commit 7bb0d53

Please sign in to comment.