Skip to content

Commit

Permalink
Do not accept empty service ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
xperimental committed Jun 22, 2016
1 parent 213fd1e commit 21d8f39
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ func (d *ServiceAPI) Put(params martini.Params, w http.ResponseWriter, r *http.R
}

func (d *ServiceAPI) Delete(params martini.Params, w http.ResponseWriter, r *http.Request) {
serviceId := params["_1"]
if !strings.HasPrefix(serviceId, "/") {
serviceId = "/" + serviceId
serviceID := params["_1"]
if len(serviceID) == 0 {
responseError(w, "can not use empty ID")
return
}

if !strings.HasPrefix(serviceID, "/") {
serviceID = "/" + serviceID
}

err := d.Storage.Delete(serviceId)
err := d.Storage.Delete(serviceID)
if err != nil {
responseError(w, err.Error())
return
Expand All @@ -89,6 +94,11 @@ func extractService(r *http.Request) (service.Service, error) {
if err != nil {
return serviceModel, errors.New("Unable to decode JSON request")
}

if len(serviceModel.Id) == 0 {
return serviceModel, errors.New("can not use empty ID")
}

if !strings.HasPrefix(serviceModel.Id, "/") {
serviceModel.Id = "/" + serviceModel.Id
}
Expand Down

0 comments on commit 21d8f39

Please sign in to comment.