Skip to content

Commit

Permalink
modify checkMaxLength
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao committed Mar 20, 2020
1 parent b56effc commit 268f040
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,11 @@ func checkMaxLength(valueField reflect.Value, tag string) error {
if err != nil {
return err
}
if maxLength < valueField.Len() {
length := valueField.Len()
if valueField.Kind().String() == "string" {
length = len([]byte(valueField.String()))
}
if maxLength < length {
errMsg := fmt.Sprintf("Length of %s is more than %d", valueField.String(), maxLength)
return errors.New(errMsg)
}
Expand Down

0 comments on commit 268f040

Please sign in to comment.