From 5c80236c0ed27af9db42b6d5b60f0d365457c7a4 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 17 Feb 2025 12:05:52 +0800 Subject: {remote_url,ssh_server}.go: Use path.Join instead of trimming and adding --- remote_url.go | 6 +++--- ssh_server.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/remote_url.go b/remote_url.go index f64d6ec..28d7dbe 100644 --- a/remote_url.go +++ b/remote_url.go @@ -2,13 +2,13 @@ package main import ( "net/url" - "strings" + "path" ) func generate_ssh_remote_url(group_name, repo_name string) string { - return strings.TrimSuffix(config.SSH.Root, "/") + "/" + url.PathEscape(group_name) + "/:/repos/" + url.PathEscape(repo_name) + return path.Join(config.SSH.Root, url.PathEscape(group_name), "/:/repos/", url.PathEscape(repo_name)) } func generate_http_remote_url(group_name, repo_name string) string { - return strings.TrimSuffix(config.HTTP.Root, "/") + "/" + url.PathEscape(group_name) + "/:/repos/" + url.PathEscape(repo_name) + return path.Join(config.HTTP.Root, url.PathEscape(group_name), "/:/repos/", url.PathEscape(repo_name)) } diff --git a/ssh_server.go b/ssh_server.go index 206bf72..63ba467 100644 --- a/ssh_server.go +++ b/ssh_server.go @@ -4,6 +4,7 @@ import ( "fmt" "net" "os" + "path" "strings" glider_ssh "github.com/gliderlabs/ssh" @@ -41,7 +42,7 @@ func serve_ssh(listener net.Listener) error { } clog.Info("Incoming SSH: " + session.RemoteAddr().String() + " " + client_public_key_string + " " + session.RawCommand()) - fmt.Fprintln(session.Stderr(), "Lindenii Forge "+VERSION+", source at "+strings.TrimSuffix(config.HTTP.Root, "/")+"/:/source/\r") + fmt.Fprintln(session.Stderr(), "Lindenii Forge "+VERSION+", source at "+path.Join(config.HTTP.Root, "/:/source/\r")) cmd := session.Command() -- cgit v1.2.3