From 0ef46ae157e9907e77367fc8851fb6ebcc8e73ea Mon Sep 17 00:00:00 2001 From: Fernando Governatore Date: Fri, 26 Jan 2018 14:31:39 -0200 Subject: [PATCH] Fixes incorrect URL for submodules that specify the remote port If the repo's host is in urlPrefix, test if there is a number after the ":" and, if there is one, consider it as a port number and ignore it in the URL returned. Fixes go-gitea/gitea#2775 Signed-off-by: Fernando Governatore --- submodule.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/submodule.go b/submodule.go index a0fe7b4a5..78d912dac 100644 --- a/submodule.go +++ b/submodule.go @@ -4,7 +4,10 @@ package git -import "strings" +import ( + "strings" + "strconv" +) // SubModule submodule is a reference on git repository type SubModule struct { @@ -58,6 +61,8 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { } // sysuser@xxx:user/repo + // or + // sysuser@xxx:port/user/repo i := strings.Index(url, "@") j := strings.LastIndex(url, ":") @@ -65,7 +70,12 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { if i > -1 && j > -1 && i < j { // fix problem with reverse proxy works only with local server if strings.Contains(urlPrefix, url[i+1:j]) { - return urlPrefix + url[j+1:] + port := strings.Index(url[j+1:], "/") + _, err := strconv.ParseInt(url[j+1:j+1 + port],10,16) + if err != nil { + return urlPrefix + url[j+1:] + } + return urlPrefix + url[j+1 + port+1:] } return "http://" + url[i+1:j] + "/" + url[j+1:] }