]> source.dussan.org Git - gitea.git/commitdiff
Fix redirect url of legacy commits route (#2825)
authorMorlinest <morlinest@gmail.com>
Thu, 2 Nov 2017 22:01:22 +0000 (23:01 +0100)
committerLauris BH <lauris@nix.lv>
Thu, 2 Nov 2017 22:01:22 +0000 (00:01 +0200)
integrations/links_test.go
modules/context/repo.go

index 7eaf1c51ef84108673af9467d9800711d4f7c1e1..e1213a2edc8beadf533c6ba280736b3e47223702 100644 (file)
@@ -7,8 +7,10 @@ package integrations
 import (
        "fmt"
        "net/http"
+       "path"
        "testing"
 
+       "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/sdk/gitea"
 
        "github.com/stretchr/testify/assert"
@@ -50,7 +52,7 @@ func TestRedirectsNoLogin(t *testing.T) {
        for link, redirectLink := range redirects {
                req := NewRequest(t, "GET", link)
                resp := MakeRequest(t, req, http.StatusFound)
-               assert.EqualValues(t, redirectLink, RedirectURL(t, resp))
+               assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), RedirectURL(t, resp))
        }
 }
 
index b2b58c4f26cc9b90d32b015f78fc5afe1f0afa43..8e0c584c822d61f7f7c9b42d4ed51de620345075 100644 (file)
@@ -521,16 +521,6 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
        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
 // of repository reference
 func RepoRefByType(refType RepoRefType) macaron.Handler {
@@ -617,7 +607,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
 
                        if refType == RepoRefLegacy {
                                // 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
                        }
                }