From 3eb57370a658a648ba504776b962d1d23cc57693 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 10 Mar 2017 23:37:25 -0500 Subject: [PATCH] api/repo: fix cannot reponse branch with slashes (#4198) --- modules/context/api.go | 2 +- routers/api/v1/api.go | 2 +- routers/api/v1/repo/branch.go | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/context/api.go b/modules/context/api.go index 500452edc..a499ec3cd 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -32,7 +32,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) { } if status == 500 { - log.Error(4, "%s: %s", title, message) + log.Error(3, "%s: %s", title, message) } ctx.JSON(status, map[string]string{ diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index df5fb5c39..6221bcd72 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -258,7 +258,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/forks", repo.ListForks) m.Group("/branches", func() { m.Get("", repo.ListBranches) - m.Get("/:branchname", repo.GetBranch) + m.Get("/*", repo.GetBranch) }) m.Group("/keys", func() { m.Combo("").Get(repo.ListDeployKeys). diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index a141921ea..1d60b7d14 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -7,15 +7,20 @@ package repo import ( api "github.com/gogits/go-gogs-client" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/routers/api/v1/convert" ) // https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch func GetBranch(ctx *context.APIContext) { - branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname")) + branch, err := ctx.Repo.Repository.GetBranch(ctx.Params("*")) if err != nil { - ctx.Error(500, "GetBranch", err) + if models.IsErrBranchNotExist(err) { + ctx.Error(404, "GetBranch", err) + } else { + ctx.Error(500, "GetBranch", err) + } return }