mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Fix "redirect link" handling (#33440)
`a%2fb` should not redirect to `a/b` --------- Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
@@ -413,8 +413,19 @@ func Home(ctx *context.Context) {
|
||||
ctx.HTML(http.StatusOK, tplRepoHome)
|
||||
}
|
||||
|
||||
// HomeRedirect redirects from /tree/* to /src/* in order to maintain a similar URL structure.
|
||||
func HomeRedirect(ctx *context.Context) {
|
||||
remainder := ctx.PathParam("*")
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(remainder))
|
||||
func RedirectRepoTreeToSrc(ctx *context.Context) {
|
||||
// Redirect "/owner/repo/tree/*" requests to "/owner/repo/src/*",
|
||||
// then use the deprecated "/src/*" handler to guess the ref type and render a file list page.
|
||||
// This is done intentionally so that Gitea's repo URL structure matches other forges (GitHub/GitLab) provide,
|
||||
// allowing us to construct submodule URLs across forges easily.
|
||||
// For example, when viewing a submodule, we can simply construct the link as:
|
||||
// * "https://gitea/owner/repo/tree/{CommitID}"
|
||||
// * "https://github/owner/repo/tree/{CommitID}"
|
||||
// * "https://gitlab/owner/repo/tree/{CommitID}"
|
||||
// Then no matter which forge the submodule is using, the link works.
|
||||
redirect := ctx.Repo.RepoLink + "/src/" + ctx.PathParamRaw("*")
|
||||
if ctx.Req.URL.RawQuery != "" {
|
||||
redirect += "?" + ctx.Req.URL.RawQuery
|
||||
}
|
||||
ctx.Redirect(redirect)
|
||||
}
|
||||
|
Reference in New Issue
Block a user