1
1
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:
wxiaoguang
2025-01-31 04:12:14 +08:00
committed by GitHub
parent f88dbf86b3
commit f24d73ab5f
7 changed files with 65 additions and 45 deletions

View File

@@ -1583,13 +1583,7 @@ func registerRoutes(m *web.Router) {
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.Home)
m.Get("/*", context.RepoRefByType(""), repo.Home) // "/*" route is deprecated, and kept for backward compatibility
}, repo.SetEditorconfigIfExists)
// Add a /tree/* path to redirect to the /src/* path, which
// will redirect to the canonical URL for that ref. This is
// included so that Gitea's repo URL structure matches what
// other forges provide, allowing clients to construct URLs
// that work across forges.
m.Get("/tree/*", repo.HomeRedirect)
m.Get("/tree/*", repo.RedirectRepoTreeToSrc) // redirect "/owner/repo/tree/*" requests to "/owner/repo/src/*"
m.Get("/forks", context.RepoRef(), repo.Forks)
m.Get("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}", repo.MustBeNotEmpty, repo.RawDiff)