Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix static path matching issue in macaron
  • Loading branch information
kminehart authored and dsotirakis committed Sep 21, 2021
1 parent c725a42 commit 2d456a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions pkg/api/dashboard_snapshot.go
Expand Up @@ -146,6 +146,9 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna
// GET /api/snapshots/:key
func GetDashboardSnapshot(c *models.ReqContext) response.Response {
key := c.Params(":key")
if len(key) == 0 {
return response.Error(404, "Snapshot not found", nil)
}
query := &models.GetDashboardSnapshotQuery{Key: key}

err := bus.Dispatch(query)
Expand Down Expand Up @@ -215,6 +218,9 @@ func deleteExternalDashboardSnapshot(externalUrl string) error {
// GET /api/snapshots-delete/:deleteKey
func DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) response.Response {
key := c.Params(":deleteKey")
if len(key) == 0 {
return response.Error(404, "Snapshot not found", nil)
}

query := &models.GetDashboardSnapshotQuery{DeleteKey: key}

Expand Down Expand Up @@ -245,6 +251,9 @@ func DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) response.Response
// DELETE /api/snapshots/:key
func DeleteDashboardSnapshot(c *models.ReqContext) response.Response {
key := c.Params(":key")
if len(key) == 0 {
return response.Error(404, "Snapshot not found", nil)
}

query := &models.GetDashboardSnapshotQuery{Key: key}

Expand Down
10 changes: 6 additions & 4 deletions pkg/macaron/router.go
Expand Up @@ -289,10 +289,12 @@ func (r *Router) SetHandlerWrapper(f func(Handler) Handler) {
func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if t, ok := r.routers[req.Method]; ok {
// Fast match for static routes
leaf := r.getLeaf(req.Method, req.URL.Path)
if leaf != nil {
leaf.handle(rw, req, nil)
return
if !strings.ContainsAny(req.URL.Path, ":*") {
leaf := r.getLeaf(req.Method, req.URL.Path)
if leaf != nil {
leaf.handle(rw, req, nil)
return
}
}

h, p, ok := t.Match(req.URL.EscapedPath())
Expand Down

0 comments on commit 2d456a6

Please sign in to comment.