Skip to content

Commit

Permalink
MB-52634:Throw an error when the value for a named parameter is set m…
Browse files Browse the repository at this point in the history
…ultiple times in an API call

Change-Id: I203684cf4cc916e206f0bc99cd4f9cad762c4902
Reviewed-on: https://review.couchbase.org/c/query/+/178099
Reviewed-by: Donald Haggart <donald.haggart@couchbase.com>
Tested-by: Dhanya Gowrish <dhanya.gowrish@couchbase.com>
  • Loading branch information
dhanyagowrish committed Jul 28, 2022
1 parent f8265ab commit 5dc336c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/http/service_request.go
Expand Up @@ -1100,6 +1100,13 @@ func newUrlArgs(req *http.Request, urlArgs *urlArgs) errors.Error {
}
if newArg[0] == '$' || newArg[0] == '@' {
delete(req.Form, arg)

// If there already exists an entry in named parameter map for the argument then the argument value has been set multiple times in the request using a different prefix - either @|$
_, ok := named[newArg[1:]]
if ok {
return errors.NewServiceErrorMultipleValues(arg)
}

switch len(val) {
case 0:
//This is an error - there _has_ to be a value for a named argument
Expand Down Expand Up @@ -1494,6 +1501,13 @@ func newJsonArgs(req *http.Request, p *jsonArgs) errors.Error {
continue
}
if newArg[0] == '$' || newArg[0] == '@' {

// If there already exists an entry in named parameter map for the argument then the argument value has been set multiple times in the request
_, ok := p.named[newArg[1:]]
if ok {
return errors.NewServiceErrorMultipleValues(newArg)
}

p.named = addNamedArg(p.named, newArg[1:], value.NewValue(val))
continue
}
Expand Down

0 comments on commit 5dc336c

Please sign in to comment.