Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a validation error when query string is malformed #3488

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion http/codegen/service_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ func buildPayloadData(e *expr.HTTPEndpointExpr, sd *ServiceData) *PayloadData {
}
if !mustValidate {
for _, q := range queryData {
if q.Validate != "" || q.Required || needConversion(q.Type) {
if q.Map || q.Validate != "" || q.Required || needConversion(q.Type) {
mustValidate = true
break
}
Expand Down
4 changes: 4 additions & 0 deletions http/codegen/templates/partial/query_map_conversion.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
if closeIdx == -1 {
err = goa.MergeErrors(err, goa.DecodePayloadError("invalid query string: missing closing bracket"))
} else {
{{- if eq .Type.KeyType.Type.Name "string" }}
key{{ .Loop }} = keyRaw[openIdx+1 : closeIdx]
{{- else }}
Expand All @@ -14,6 +17,7 @@
{{- if gt .Depth 0 }}
keyRaw = keyRaw[closeIdx+1:]
{{- end }}
}
}
{{- if eq .Type.ElemType.Type.Name "string" }}
{{ .VarName }}[key{{ .Loop }}] = valRaw[0]
Expand Down
28 changes: 18 additions & 10 deletions http/codegen/testdata/multipart_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,16 @@ func NewServiceMultipartWithParamMethodMultipartWithParamDecoder(mux goahttp.Mux
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keyaRaw := keyRaw[openIdx+1 : closeIdx]
v, err2 := strconv.ParseInt(keyaRaw, 10, strconv.IntSize)
if err2 != nil {
err = goa.MergeErrors(err, goa.InvalidFieldTypeError("query", keyaRaw, "integer"))
if closeIdx == -1 {
err = goa.MergeErrors(err, goa.DecodePayloadError("invalid query string: missing closing bracket"))
} else {
keyaRaw := keyRaw[openIdx+1 : closeIdx]
v, err2 := strconv.ParseInt(keyaRaw, 10, strconv.IntSize)
if err2 != nil {
err = goa.MergeErrors(err, goa.InvalidFieldTypeError("query", keyaRaw, "integer"))
}
keya = int(v)
}
keya = int(v)
}
c2[keya] = valRaw
}
Expand Down Expand Up @@ -221,12 +225,16 @@ func NewServiceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersD
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keyaRaw := keyRaw[openIdx+1 : closeIdx]
v, err2 := strconv.ParseInt(keyaRaw, 10, strconv.IntSize)
if err2 != nil {
err = goa.MergeErrors(err, goa.InvalidFieldTypeError("query", keyaRaw, "integer"))
if closeIdx == -1 {
err = goa.MergeErrors(err, goa.DecodePayloadError("invalid query string: missing closing bracket"))
} else {
keyaRaw := keyRaw[openIdx+1 : closeIdx]
v, err2 := strconv.ParseInt(keyaRaw, 10, strconv.IntSize)
if err2 != nil {
err = goa.MergeErrors(err, goa.InvalidFieldTypeError("query", keyaRaw, "integer"))
}
keya = int(v)
}
keya = int(v)
}
c2[keya] = valRaw
}
Expand Down
Loading