Skip to content

Commit

Permalink
Merge pull request #108 from heetch/fix/uuid-zero-object
Browse files Browse the repository at this point in the history
Allow UUID empty string decoding as empty UUID object
  • Loading branch information
sixstone-qq authored Nov 25, 2021
2 parents 4f2c94d + 8213d14 commit 34be94a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ func (d *decoder) eval(target reflect.Value) {
}
case vm.String:
if target.Type() == uuidType {
if frame.String == "" {
// We produce the empty string "" when encoding zero UUID value,
// so allow it when decoding too.
target.Set(reflect.ValueOf(gouuid.UUID{}))
break
}
val, err := gouuid.Parse(frame.String)
if err != nil {
d.error(fmt.Errorf("invalid UUID in Avro encoding: %w", err))
Expand Down
5 changes: 5 additions & 0 deletions gotype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func TestGoTypeWithUUID(t *testing.T) {
c.Assert(err, qt.IsNil)
c.Assert(x, qt.DeepEquals, R{})
}

var x R
_, err = avro.Unmarshal(data, &x, wType)
c.Assert(err, qt.IsNil)
c.Assert(x, qt.DeepEquals, R{})
})

}
Expand Down

0 comments on commit 34be94a

Please sign in to comment.