Fix redirect url of legacy commits route (#2825)

tokarchuk/v1.17
Morlinest 7 years ago committed by Lauris BH
parent 529f9d03ce
commit 1f04c00e2f
  1. 4
      integrations/links_test.go
  2. 12
      modules/context/repo.go

@ -7,8 +7,10 @@ package integrations
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"path"
"testing" "testing"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/sdk/gitea" api "code.gitea.io/sdk/gitea"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -50,7 +52,7 @@ func TestRedirectsNoLogin(t *testing.T) {
for link, redirectLink := range redirects { for link, redirectLink := range redirects {
req := NewRequest(t, "GET", link) req := NewRequest(t, "GET", link)
resp := MakeRequest(t, req, http.StatusFound) resp := MakeRequest(t, req, http.StatusFound)
assert.EqualValues(t, redirectLink, RedirectURL(t, resp)) assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), RedirectURL(t, resp))
} }
} }

@ -521,16 +521,6 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
return "" return ""
} }
// URL to redirect to for deprecated URL scheme
func repoRefRedirect(ctx *Context) string {
urlPath := ctx.Req.URL.String()
idx := strings.LastIndex(urlPath, ctx.Params("*"))
if idx < 0 {
idx = len(urlPath)
}
return path.Join(urlPath[:idx], ctx.Repo.BranchNameSubURL())
}
// RepoRefByType handles repository reference name for a specific type // RepoRefByType handles repository reference name for a specific type
// of repository reference // of repository reference
func RepoRefByType(refType RepoRefType) macaron.Handler { func RepoRefByType(refType RepoRefType) macaron.Handler {
@ -617,7 +607,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
if refType == RepoRefLegacy { if refType == RepoRefLegacy {
// redirect from old URL scheme to new URL scheme // redirect from old URL scheme to new URL scheme
ctx.Redirect(repoRefRedirect(ctx)) ctx.Redirect(path.Join(setting.AppSubURL, strings.TrimSuffix(ctx.Req.URL.String(), ctx.Params("*")), ctx.Repo.BranchNameSubURL()))
return return
} }
} }

Loading…
Cancel
Save