Skip to content

Commit d8f5784

Browse files
Redirect .wiki/* ui link to /wiki (#18831)
Redirect .wiki/* ui link to /wiki fix #18590 Signed-off-by: a1012112796 <[email protected]> Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Andrew Thornton <[email protected]>
1 parent 5248232 commit d8f5784

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

modules/context/repo.go

+20
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,26 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
441441
ctx.Repo.Owner = owner
442442
ctx.Data["Username"] = ctx.Repo.Owner.Name
443443

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

0 commit comments

Comments
 (0)