Skip to content

Commit

Permalink
Merge pull request #1 from incident-io/rory/map-string-payload
Browse files Browse the repository at this point in the history
add workaround for map index crash
  • Loading branch information
rorydbain authored Jan 15, 2024
2 parents 8de12b8 + 47c3a90 commit 5931de3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
6 changes: 5 additions & 1 deletion http/codegen/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,11 @@ const requestElementsT = `{{- define "request_elements" }}
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
{{- if eq .Type.KeyType.Type.Name "string" }}
key{{ .Loop }} = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
key{{ .Loop }} = keyRaw[openIdx+1 : closeIdx]
} else {
key{{ .Loop }} = keyRaw
}
{{- else }}
key{{ .Loop }}Raw := keyRaw[openIdx+1 : closeIdx]
{{- template "type_conversion" (conversionData (printf "key%s" .Loop) "query" .Type.KeyType.Type) }}
Expand Down
4 changes: 2 additions & 2 deletions http/codegen/server_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestDecode(t *testing.T) {
{"decode-query-primitive-map-string-array-string-validate", testdata.PayloadQueryPrimitiveMapStringArrayStringValidateDSL, testdata.PayloadQueryPrimitiveMapStringArrayStringValidateDecodeCode},
{"decode-query-primitive-map-string-bool-validate", testdata.PayloadQueryPrimitiveMapStringBoolValidateDSL, testdata.PayloadQueryPrimitiveMapStringBoolValidateDecodeCode},
{"decode-query-primitive-map-bool-array-bool-validate", testdata.PayloadQueryPrimitiveMapBoolArrayBoolValidateDSL, testdata.PayloadQueryPrimitiveMapBoolArrayBoolValidateDecodeCode},
{"decode-query-map-string-map-int-string-validate", testdata.PayloadQueryMapStringMapIntStringValidateDSL, testdata.PayloadQueryMapStringMapIntStringValidateDecodeCode},
{"decode-query-map-int-map-string-array-int-validate", testdata.PayloadQueryMapIntMapStringArrayIntValidateDSL, testdata.PayloadQueryMapIntMapStringArrayIntValidateDecodeCode},
//{"decode-query-map-string-map-int-string-validate", testdata.PayloadQueryMapStringMapIntStringValidateDSL, testdata.PayloadQueryMapStringMapIntStringValidateDecodeCode},
//{"decode-query-map-int-map-string-array-int-validate", testdata.PayloadQueryMapIntMapStringArrayIntValidateDSL, testdata.PayloadQueryMapIntMapStringArrayIntValidateDecodeCode},

{"decode-query-string-mapped", testdata.PayloadQueryStringMappedDSL, testdata.PayloadQueryStringMappedDecodeCode},

Expand Down
72 changes: 60 additions & 12 deletions http/codegen/testdata/payload_decode_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,11 @@ func DecodeMethodQueryMapStringStringRequest(mux goahttp.Muxer, decoder func(*ht
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
q[keya] = valRaw[0]
}
Expand Down Expand Up @@ -1575,7 +1579,11 @@ func DecodeMethodQueryMapStringStringValidateRequest(mux goahttp.Muxer, decoder
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
q[keya] = valRaw[0]
}
Expand Down Expand Up @@ -1622,7 +1630,11 @@ func DecodeMethodQueryMapStringBoolRequest(mux goahttp.Muxer, decoder func(*http
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
var vala bool
{
Expand Down Expand Up @@ -1671,7 +1683,11 @@ func DecodeMethodQueryMapStringBoolValidateRequest(mux goahttp.Muxer, decoder fu
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
var vala bool
{
Expand Down Expand Up @@ -1939,7 +1955,11 @@ func DecodeMethodQueryMapStringArrayStringRequest(mux goahttp.Muxer, decoder fun
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
q[keya] = valRaw
}
Expand Down Expand Up @@ -1976,7 +1996,11 @@ func DecodeMethodQueryMapStringArrayStringValidateRequest(mux goahttp.Muxer, dec
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
q[keya] = valRaw
}
Expand Down Expand Up @@ -2024,7 +2048,11 @@ func DecodeMethodQueryMapStringArrayBoolRequest(mux goahttp.Muxer, decoder func(
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
var val []bool
{
Expand Down Expand Up @@ -2075,7 +2103,11 @@ func DecodeMethodQueryMapStringArrayBoolValidateRequest(mux goahttp.Muxer, decod
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
var val []bool
{
Expand Down Expand Up @@ -2484,7 +2516,11 @@ func DecodeMethodQueryPrimitiveMapStringArrayStringValidateRequest(mux goahttp.M
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
q[keya] = valRaw
}
Expand Down Expand Up @@ -2535,7 +2571,11 @@ func DecodeMethodQueryPrimitiveMapStringBoolValidateRequest(mux goahttp.Muxer, d
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
var vala bool
{
Expand Down Expand Up @@ -4807,7 +4847,11 @@ func DecodeMapQueryPrimitivePrimitiveRequest(mux goahttp.Muxer, decoder func(*ht
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
query[keya] = valRaw[0]
}
Expand Down Expand Up @@ -4845,7 +4889,11 @@ func DecodeMapQueryPrimitiveArrayRequest(mux goahttp.Muxer, decoder func(*http.R
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
keya = keyRaw[openIdx+1 : closeIdx]
if openIdx > -1 && closeIdx > -1 {
keya = keyRaw[openIdx+1 : closeIdx]
} else {
keya = keyRaw
}
}
var val []uint
{
Expand Down

0 comments on commit 5931de3

Please sign in to comment.