Skip to content

Commit 1f04c00

Browse files
Morlinestlafriks
authored andcommitted
Fix redirect url of legacy commits route (#2825)
1 parent 529f9d0 commit 1f04c00

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

integrations/links_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ package integrations
77
import (
88
"fmt"
99
"net/http"
10+
"path"
1011
"testing"
1112

13+
"code.gitea.io/gitea/modules/setting"
1214
api "code.gitea.io/sdk/gitea"
1315

1416
"github.com/stretchr/testify/assert"
@@ -50,7 +52,7 @@ func TestRedirectsNoLogin(t *testing.T) {
5052
for link, redirectLink := range redirects {
5153
req := NewRequest(t, "GET", link)
5254
resp := MakeRequest(t, req, http.StatusFound)
53-
assert.EqualValues(t, redirectLink, RedirectURL(t, resp))
55+
assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), RedirectURL(t, resp))
5456
}
5557
}
5658

modules/context/repo.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -521,16 +521,6 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
521521
return ""
522522
}
523523

524-
// URL to redirect to for deprecated URL scheme
525-
func repoRefRedirect(ctx *Context) string {
526-
urlPath := ctx.Req.URL.String()
527-
idx := strings.LastIndex(urlPath, ctx.Params("*"))
528-
if idx < 0 {
529-
idx = len(urlPath)
530-
}
531-
return path.Join(urlPath[:idx], ctx.Repo.BranchNameSubURL())
532-
}
533-
534524
// RepoRefByType handles repository reference name for a specific type
535525
// of repository reference
536526
func RepoRefByType(refType RepoRefType) macaron.Handler {
@@ -617,7 +607,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
617607

618608
if refType == RepoRefLegacy {
619609
// redirect from old URL scheme to new URL scheme
620-
ctx.Redirect(repoRefRedirect(ctx))
610+
ctx.Redirect(path.Join(setting.AppSubURL, strings.TrimSuffix(ctx.Req.URL.String(), ctx.Params("*")), ctx.Repo.BranchNameSubURL()))
621611
return
622612
}
623613
}

0 commit comments

Comments
 (0)