Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit a80f846

Browse files
author
Fernando Governatore
committed
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 <[email protected]>
1 parent 6798d0f commit a80f846

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

submodule.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package git
66

7-
import "strings"
7+
import (
8+
"strings"
9+
"strconv"
10+
)
811

912
// SubModule submodule is a reference on git repository
1013
type SubModule struct {
@@ -58,14 +61,22 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
5861
}
5962

6063
// sysuser@xxx:user/repo
64+
// or
65+
// sysuser@xxx:port/user/repo
6166
i := strings.Index(url, "@")
6267
j := strings.LastIndex(url, ":")
6368

6469
// Only process when i < j because git+ssh://[email protected]/npploader.git
6570
if i > -1 && j > -1 && i < j {
6671
// fix problem with reverse proxy works only with local server
6772
if strings.Contains(urlPrefix, url[i+1:j]) {
68-
return urlPrefix + url[j+1:]
73+
port := strings.Index(url[j+1:], "/")
74+
_, err := strconv.ParseInt(url[j+1:j+1 + port],10,16)
75+
if err != nil {
76+
return urlPrefix + url[j+1:]
77+
} else {
78+
return urlPrefix + url[j+1 + port+1:]
79+
}
6980
}
7081
return "http://" + url[i+1:j] + "/" + url[j+1:]
7182
}

0 commit comments

Comments
 (0)