From f0fd185f14fdcc13a0ec50f3134515623abbf0a2 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Tue, 21 Apr 2026 10:04:01 +0800 Subject: [PATCH] Fix AppFullLink (#37325) (#37328) Backport #37325 by @lunny Fix a bug the checkout command line hint become `git fetch -u https://gitea.combircni/tea` Co-authored-by: Lunny Xiao --- services/context/context_template.go | 2 +- services/context/context_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/services/context/context_template.go b/services/context/context_template.go index 4e28c0f7dfd..aa07c834309 100644 --- a/services/context/context_template.go +++ b/services/context/context_template.go @@ -81,5 +81,5 @@ func (c TemplateContext) AppFullLink(link ...string) template.URL { if len(link) == 0 { return template.URL(s) } - return template.URL(s + strings.TrimPrefix(link[0], "/")) + return template.URL(s + "/" + strings.TrimPrefix(link[0], "/")) } diff --git a/services/context/context_test.go b/services/context/context_test.go index 54044644f07..aaf79de7163 100644 --- a/services/context/context_test.go +++ b/services/context/context_test.go @@ -49,3 +49,17 @@ func TestRedirectToCurrentSite(t *testing.T) { }) } } + +func TestAppFullLink(t *testing.T) { + setting.IsInTesting = true + defer test.MockVariableValue(&setting.AppURL, "https://gitea.example.com/sub/")() + defer test.MockVariableValue(&setting.AppSubURL, "/sub")() + defer test.MockVariableValue(&setting.PublicURLDetection, setting.PublicURLNever)() + + req := httptest.NewRequest(http.MethodGet, "https://gitea.example.com/sub/", nil) + tmplCtx := NewTemplateContext(req.Context(), req) + + assert.Equal(t, "https://gitea.example.com/sub", string(tmplCtx.AppFullLink())) + assert.Equal(t, "https://gitea.example.com/sub/user/repo", string(tmplCtx.AppFullLink("user/repo"))) + assert.Equal(t, "https://gitea.example.com/sub/user/repo", string(tmplCtx.AppFullLink("/user/repo"))) +}