mirror of https://github.com/golang-jwt/jwt.git
Using jwt's native `ErrInvalidType` instead of `json.UnsupportedTypeError` (#316)
Previously, when parsing claim values, we used `json.UnsupportedTypeError` to denote if a claim string value is not of the correct type. However, this could lead to panics if a nil value is present and the `Error` function of the `json.UnsupportedTypeError` is called, which does not check for nil types. Instead, we just now use `ErrInvalidType` similar to the map claims. Fixes #315
This commit is contained in:
parent
5e00fbc8e7
commit
0da169122f
5
types.go
5
types.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"reflect"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -121,14 +120,14 @@ func (s *ClaimStrings) UnmarshalJSON(data []byte) (err error) {
|
||||||
for _, vv := range v {
|
for _, vv := range v {
|
||||||
vs, ok := vv.(string)
|
vs, ok := vv.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return &json.UnsupportedTypeError{Type: reflect.TypeOf(vv)}
|
return ErrInvalidType
|
||||||
}
|
}
|
||||||
aud = append(aud, vs)
|
aud = append(aud, vs)
|
||||||
}
|
}
|
||||||
case nil:
|
case nil:
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return &json.UnsupportedTypeError{Type: reflect.TypeOf(v)}
|
return ErrInvalidType
|
||||||
}
|
}
|
||||||
|
|
||||||
*s = aud
|
*s = aud
|
||||||
|
|
Loading…
Reference in New Issue