Skip to content

Commit

Permalink
handle nil input in UUID factory (#101)
Browse files Browse the repository at this point in the history
Fix #100

Signed-off-by: Thomas Fossati <[email protected]>
Co-authored-by: Thomas Fossati <[email protected]>
  • Loading branch information
thomas-fossati and thomas-fossati authored Dec 14, 2023
1 parent 9f5f2a2 commit 9a6edcb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions comid/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,18 @@ func TestRegisterMkeyType(t *testing.T) {
err = RegisterMkeyType(99996, newTestMkey)
assert.NoError(t, err)
}

func TestMkey_UnmarshalJSON_regression_issue_100(t *testing.T) {
u := `31fb5abf-023e-4992-aa4e-95f9c1503bfa`

tv := []byte(fmt.Sprintf(`{ "type": "uuid", "value": %q }`, u))

expected, err := NewMkeyUUID(u)
require.NoError(t, err)

actual := &Mkey{}
err = actual.UnmarshalJSON(tv)

assert.Nil(t, err)
assert.Equal(t, expected, actual)
}
4 changes: 4 additions & 0 deletions comid/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ type TaggedUUID UUID
func NewTaggedUUID(val any) (*TaggedUUID, error) {
var ret TaggedUUID

if val == nil {
return &ret, nil
}

switch t := val.(type) {
case string:
u, err := ParseUUID(t)
Expand Down

0 comments on commit 9a6edcb

Please sign in to comment.