Skip to content

Commit

Permalink
[gapi] add pattern body validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-ba committed Sep 27, 2023
1 parent 2e0de54 commit ecf8f2c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions middleware/body_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (m BodyDecoder) Wrap(h handler.Handler) handler.Handler {
return nil, errors.InternalServerError("pattern_must_be_regex", "pattern must contain a regular expression")
}

if !val.Field(i).CanInterface() {
return nil, errors.InternalServerError("interface_failed", "interface cannot be used without panicking")
}

fieldValue := val.Field(i).Interface()
if !rex.MatchString(fmt.Sprintf("%v", fieldValue)) {
return nil, errors.BadRequest("body_validation_failed", "field %s does not match the required pattern", typeOfFieldI.Name)
Expand Down

0 comments on commit ecf8f2c

Please sign in to comment.