From b2c17ef5d72d3cba18a1ae82b5bfb34ecb220cfe 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 Fixes go-gitea/gitea#2775 --- submodule.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/submodule.go b/submodule.go index a0fe7b4a5..cf468b490 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,13 @@ 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:] + } else { + return urlPrefix + url[j+1 + port+1:] + } } return "http://" + url[i+1:j] + "/" + url[j+1:] }