Goit

Simple and lightweight Git web server
git clone https://git.omkov.net/Goit
git clone [email protected]:Goit
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2025-01-04 05:20:34
Commita12579f06473bd31846118c3ac7fa9807452ec7f
Parentde239c08420f9e6dec68d1283f3ebf03c639ee5b

Fix repo header crash if host doesn't have a port

Diffstat

M src/repo/repo.go | 7 ++++++-

1 files changed, 6 insertions, 1 deletions

diff --git a/src/repo/repo.go b/src/repo/repo.go
index 8ac9b27..1b6fb6d 100644
--- a/src/repo/repo.go
+++ b/src/repo/repo.go
@@ -20,13 +20,18 @@ type HeaderFields struct {
 }
 
 func GetHeaderFields(auth bool, user *goit.User, repo *goit.Repo, host string) HeaderFields {
+	var hostWithoutPort = host
+	if strings.LastIndex(host, ":") != -1 {
+		hostWithoutPort = host[:strings.LastIndex(host, ":")]
+	}
+
 	return HeaderFields{
 		Name: repo.Name, Description: repo.Description,
 		URL:       util.If(goit.Conf.UsesHTTPS, "https://", "http://") + host + "/" + repo.Name,
 		Editable:  (auth && repo.OwnerId == user.Id),
 		Mirror:    util.If(repo.IsMirror, repo.Upstream, ""),
 		EnableSSH: goit.Conf.EnableSSH,
-		SSH:       goit.Conf.SSHUsername + "@" + host[:strings.LastIndex(host, ":")] + ":" + repo.Name,
+		SSH:       goit.Conf.SSHUsername + "@" + hostWithoutPort + ":" + repo.Name,
 	}
 }