fix: nil pointer dereference on UserInfoAddress (#207)
* oidc: add test case to reproduce #203 Running the tests will always result in a nil pointer dereference on UserInfoAddress. Co-authored-by: Livio Spring <livio.a@gmail.com> * fix: nil pointer dereference on UserInfoAddress userinfo.UnmarshalJSON now only sets the Address field if it was present in the json. userinfo.GetAddress will always return a non-nil value of UserInfoAddress to allow for safe chaining of Get functions. Fixes #203 --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
parent
1535ea4f6c
commit
fa222c5efb
2 changed files with 44 additions and 1 deletions
|
@ -167,6 +167,9 @@ func (u *userinfo) IsPhoneNumberVerified() bool {
|
|||
}
|
||||
|
||||
func (u *userinfo) GetAddress() UserInfoAddress {
|
||||
if u.Address == nil {
|
||||
return &userInfoAddress{}
|
||||
}
|
||||
return u.Address
|
||||
}
|
||||
|
||||
|
@ -389,7 +392,11 @@ func (u *userinfo) UnmarshalJSON(data []byte) error {
|
|||
if err := json.Unmarshal(data, &a); err != nil {
|
||||
return err
|
||||
}
|
||||
u.Address = a.Address
|
||||
|
||||
if a.Address != nil {
|
||||
u.Address = a.Address
|
||||
}
|
||||
|
||||
u.UpdatedAt = Time(time.Unix(a.UpdatedAt, 0).UTC())
|
||||
|
||||
if err := json.Unmarshal(data, &u.claims); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue