Skip to content

Commit

Permalink
Merge pull request #17 from seantcanavan/fix_unset_issue
Browse files Browse the repository at this point in the history
fix issue where unset strings would attempt to cause a conversion to a mongodb id
  • Loading branch information
seantcanavan authored Jan 2, 2024
2 parents 78ca3cd + b1c5bea commit ab0d1a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lambda_router/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func unmarshalField(
strVal, ok := params[param]
strVals, okMulti := multiParam[param]

if !ok && !okMulti {
// check for empty / unset values and return no error if so
if !ok && !okMulti || (strVal == "" && strVals == nil) {
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions lambda_router/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ func Test_UnmarshalReq(t *testing.T) {
)
require.NoError(t, err)
})
t.Run("valid input unset values", func(t *testing.T) {
var input mockListReq
err := UnmarshalReq(
events.APIGatewayProxyRequest{
QueryStringParameters: map[string]string{
"mongoId": "",
},
},
false,
&input,
)
require.NoError(t, err)
})

t.Run("invalid path&query input", func(t *testing.T) {
var input mockListReq
Expand Down

0 comments on commit ab0d1a6

Please sign in to comment.