Skip to content

Commit a957fcb

Browse files
a1012112796zeripath
andcommitted
Redirect .wiki/* ui link to /wiki (go-gitea#18831)
Backport go-gitea#18831 Redirect .wiki/* ui link to /wiki fix go-gitea#18590 Signed-off-by: a1012112796 <[email protected]> Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Andrew Thornton <[email protected]>
1 parent bb0e212 commit a957fcb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

modules/context/repo.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,26 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
440440
ctx.Repo.Owner = owner
441441
ctx.Data["Username"] = ctx.Repo.Owner.Name
442442

443+
// redirect link to wiki
444+
if strings.HasSuffix(repoName, ".wiki") {
445+
// ctx.Req.URL.Path does not have the preceding appSubURL - any redirect must have this added
446+
// Now we happen to know that all of our paths are: /:username/:reponame/whatever_else
447+
originalRepoName := ctx.Params(":reponame")
448+
redirectRepoName := strings.TrimSuffix(repoName, ".wiki")
449+
redirectRepoName += originalRepoName[len(redirectRepoName)+5:]
450+
redirectPath := strings.Replace(
451+
ctx.Req.URL.EscapedPath(),
452+
url.PathEscape(userName)+"/"+url.PathEscape(originalRepoName),
453+
url.PathEscape(userName)+"/"+url.PathEscape(redirectRepoName)+"/wiki",
454+
1,
455+
)
456+
if ctx.Req.URL.RawQuery != "" {
457+
redirectPath += "?" + ctx.Req.URL.RawQuery
458+
}
459+
ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
460+
return
461+
}
462+
443463
// Get repository.
444464
repo, err := repo_model.GetRepositoryByName(owner.ID, repoName)
445465
if err != nil {

0 commit comments

Comments
 (0)