Skip to content

Commit 19626b9

Browse files
zeripathlafriks
andauthored
Manage port in submodule refurl (go-gitea#11305) (go-gitea#11323)
* Manage port in submodule refurl Fix go-gitea#11304 Signed-off-by: Andrew Thornton <[email protected]> * fix lint Signed-off-by: Andrew Thornton <[email protected]> * URLJoin is causes a cyclic dependency and possibly isn't what what we want anyway Signed-off-by: Andrew Thornton <[email protected]> * Protect against leading .. in scp syntax Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Lauris BH <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 91e6a7f commit 19626b9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/git/submodule.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ func getRefURL(refURL, urlPrefix, repoFullName string) string {
5252
urlPrefixHostname = prefixURL.Host
5353
}
5454

55+
if strings.HasSuffix(urlPrefix, "/") {
56+
urlPrefix = urlPrefix[:len(urlPrefix)-1]
57+
}
58+
5559
// FIXME: Need to consider branch - which will require changes in modules/git/commit.go:GetSubModules
5660
// Relative url prefix check (according to git submodule documentation)
5761
if strings.HasPrefix(refURI, "./") || strings.HasPrefix(refURI, "../") {
58-
return urlPrefix + path.Clean(path.Join(repoFullName, refURI))
62+
return urlPrefix + path.Clean(path.Join("/", repoFullName, refURI))
5963
}
6064

6165
if !strings.Contains(refURI, "://") {
@@ -73,7 +77,7 @@ func getRefURL(refURL, urlPrefix, repoFullName string) string {
7377
}
7478

7579
if urlPrefixHostname == refHostname {
76-
return prefixURL.Scheme + "://" + urlPrefixHostname + path.Join(prefixURL.Path, path.Clean(pth))
80+
return urlPrefix + path.Clean(path.Join("/", pth))
7781
}
7882
return "http://" + refHostname + pth
7983
}
@@ -94,7 +98,7 @@ func getRefURL(refURL, urlPrefix, repoFullName string) string {
9498
for _, scheme := range supportedSchemes {
9599
if ref.Scheme == scheme {
96100
if urlPrefixHostname == refHostname {
97-
return prefixURL.Scheme + "://" + prefixURL.Host + path.Join(prefixURL.Path, ref.Path)
101+
return urlPrefix + path.Clean(path.Join("/", ref.Path))
98102
} else if ref.Scheme == "http" || ref.Scheme == "https" {
99103
if len(ref.User.Username()) > 0 {
100104
return ref.Scheme + "://" + fmt.Sprintf("%v", ref.User) + "@" + ref.Host + ref.Path

0 commit comments

Comments
 (0)