Skip to content

Commit 69ac379

Browse files
tkoolenomus
authored andcommitted
Fix #30876, make GITHUB_REGEX match ssh://git@github.com URLs. (#30907)
* Fix #30876, make GITHUB_REGEX match ssh://git@github.com URLs. * Apply suggestions from code review Co-Authored-By: tkoolen <koolen.twan@gmail.com> * Suggested test changes.
1 parent 5aa2462 commit 69ac379

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

stdlib/LibGit2/src/LibGit2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using Base.Printf: @printf
1212
export with, GitRepo, GitConfig
1313

1414
const GITHUB_REGEX =
15-
r"^(?:git@|git://|https://(?:[\w\.\+\-]+@)?)github.com[:/](([^/].+)/(.+?))(?:\.git)?$"i
15+
r"^(?:(?:ssh://)?git@|git://|https://(?:[\w\.\+\-]+@)?)github.com[:/](([^/].+)/(.+?))(?:\.git)?$"i
1616

1717
const REFCOUNT = Threads.Atomic{Int}(0)
1818

stdlib/LibGit2/test/libgit2.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,27 @@ end
570570
@test !LibGit2.ismatch("https://@github.com", cred)
571571
Base.shred!(cred)
572572
end
573+
574+
@testset "GITHUB_REGEX" begin
575+
github_regex_test = function(url, user, repo)
576+
m = match(LibGit2.GITHUB_REGEX, url)
577+
@test m !== nothing
578+
@test m[1] == "$user/$repo"
579+
@test m[2] == user
580+
@test m[3] == repo
581+
end
582+
user = "User"
583+
repo = "Repo"
584+
github_regex_test("git@github.com/$user/$repo.git", user, repo)
585+
github_regex_test("https://github.com/$user/$repo.git", user, repo)
586+
github_regex_test("https://username@github.com/$user/$repo.git", user, repo)
587+
github_regex_test("ssh://git@github.com/$user/$repo.git", user, repo)
588+
github_regex_test("git@github.com/$user/$repo", user, repo)
589+
github_regex_test("https://github.com/$user/$repo", user, repo)
590+
github_regex_test("https://username@github.com/$user/$repo", user, repo)
591+
github_regex_test("ssh://git@github.com/$user/$repo", user, repo)
592+
@test !occursin(LibGit2.GITHUB_REGEX, "git@notgithub.com/$user/$repo.git")
593+
end
573594
end
574595

575596
mktempdir() do dir

0 commit comments

Comments
 (0)