From 4609eba2e7683acde13231fb02747e3b2e09ff45 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 26 Jul 2020 22:31:28 +0200 Subject: Fix ipv6 parsing (#12321) * Fix ipv6 parsing * Update modules/setting/setting.go Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH Co-authored-by: Lunny Xiao Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick --- models/repo.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/repo.go b/models/repo.go index 36662825c5..b2b6e1a26f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -17,6 +17,7 @@ import ( _ "image/jpeg" "image/png" "io/ioutil" + "net" "net/url" "os" "path" @@ -969,12 +970,21 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink { } cl := new(CloneLink) + + // if we have a ipv6 literal we need to put brackets around it + // for the git cloning to work. + sshDomain := setting.SSH.Domain + ip := net.ParseIP(setting.SSH.Domain) + if ip != nil && ip.To4() == nil { + sshDomain = "[" + setting.SSH.Domain + "]" + } + if setting.SSH.Port != 22 { - cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.OwnerName, repoName) + cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, net.JoinHostPort(setting.SSH.Domain, strconv.Itoa(setting.SSH.Port)), repo.OwnerName, repoName) } else if setting.Repository.UseCompatSSHURI { - cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName) + cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName) } else { - cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName) + cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName) } cl.HTTPS = ComposeHTTPSCloneURL(repo.OwnerName, repoName) return cl -- cgit v1.2.3