mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Clarify path param naming (#32969)
In history (from some legacy frameworks), both `:name` and `name` are supported as path path name, `:name` is an alias to `name`. To make code consistent, now we should only use `name` but not `:name`. Also added panic check in related functions to make sure the name won't be abused in case some downstreams still use them.
This commit is contained in:
@@ -24,8 +24,8 @@ var tplCherryPick templates.TplName = "repo/editor/cherry_pick"
|
||||
|
||||
// CherryPick handles cherrypick GETs
|
||||
func CherryPick(ctx *context.Context) {
|
||||
ctx.Data["SHA"] = ctx.PathParam(":sha")
|
||||
cherryPickCommit, err := ctx.Repo.GitRepo.GetCommit(ctx.PathParam(":sha"))
|
||||
ctx.Data["SHA"] = ctx.PathParam("sha")
|
||||
cherryPickCommit, err := ctx.Repo.GitRepo.GetCommit(ctx.PathParam("sha"))
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("Missing Commit", err)
|
||||
@@ -37,7 +37,7 @@ func CherryPick(ctx *context.Context) {
|
||||
|
||||
if ctx.FormString("cherry-pick-type") == "revert" {
|
||||
ctx.Data["CherryPickType"] = "revert"
|
||||
ctx.Data["commit_summary"] = "revert " + ctx.PathParam(":sha")
|
||||
ctx.Data["commit_summary"] = "revert " + ctx.PathParam("sha")
|
||||
ctx.Data["commit_message"] = "revert " + cherryPickCommit.Message()
|
||||
} else {
|
||||
ctx.Data["CherryPickType"] = "cherry-pick"
|
||||
@@ -66,7 +66,7 @@ func CherryPick(ctx *context.Context) {
|
||||
func CherryPickPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CherryPickForm)
|
||||
|
||||
sha := ctx.PathParam(":sha")
|
||||
sha := ctx.PathParam("sha")
|
||||
ctx.Data["SHA"] = sha
|
||||
if form.Revert {
|
||||
ctx.Data["CherryPickType"] = "revert"
|
||||
@@ -140,7 +140,7 @@ func CherryPickPost(ctx *context.Context) {
|
||||
if form.Revert {
|
||||
if err := git.GetReverseRawDiff(ctx, ctx.Repo.Repository.RepoPath(), sha, buf); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam(":sha")+" does not exist."))
|
||||
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam("sha")+" does not exist."))
|
||||
return
|
||||
}
|
||||
ctx.ServerError("GetRawDiff", err)
|
||||
@@ -149,7 +149,7 @@ func CherryPickPost(ctx *context.Context) {
|
||||
} else {
|
||||
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, git.RawDiffType("patch"), buf); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam(":sha")+" does not exist."))
|
||||
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam("sha")+" does not exist."))
|
||||
return
|
||||
}
|
||||
ctx.ServerError("GetRawDiff", err)
|
||||
|
Reference in New Issue
Block a user