From 23cf34eb3a33195494124eae0b3efe1ab6f43053 Mon Sep 17 00:00:00 2001 From: David Sharnoff Date: Thu, 31 Oct 2024 14:04:03 -0700 Subject: [PATCH] ignore all unmarshal errors from locale --- pkg/oidc/types.go | 15 ++++----------- pkg/oidc/types_test.go | 8 +++++--- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/pkg/oidc/types.go b/pkg/oidc/types.go index e7292e67..70634269 100644 --- a/pkg/oidc/types.go +++ b/pkg/oidc/types.go @@ -3,7 +3,6 @@ package oidc import ( "database/sql/driver" "encoding/json" - "errors" "fmt" "reflect" "strings" @@ -78,22 +77,16 @@ func (l *Locale) MarshalJSON() ([]byte, error) { } // UnmarshalJSON implements json.Unmarshaler. -// When [language.ValueError] is encountered, the containing tag will be set +// All unmarshal errors for are ignored. +// When an error is encountered, the containing tag will be set // to an empty value (language "und") and no error will be returned. // This state can be checked with the `l.Tag().IsRoot()` method. func (l *Locale) UnmarshalJSON(data []byte) error { err := json.Unmarshal(data, &l.tag) - if err == nil { - return nil - } - - // catch "well-formed but unknown" errors - var target language.ValueError - if errors.As(err, &target) { + if err != nil { l.tag = language.Tag{} - return nil } - return err + return nil } type Locales []language.Tag diff --git a/pkg/oidc/types_test.go b/pkg/oidc/types_test.go index df93a738..c7ce0eea 100644 --- a/pkg/oidc/types_test.go +++ b/pkg/oidc/types_test.go @@ -232,9 +232,11 @@ func TestLocale_UnmarshalJSON(t *testing.T) { }, }, { - name: "bad form, error", - input: `{"locale": "g!!!!!"}`, - wantErr: true, + name: "bad form, error", + input: `{"locale": "g!!!!!"}`, + want: dst{ + Locale: &Locale{}, + }, }, }