google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.16k stars 362 forks source link

chore(tests): Add json.Unmarshal test with empty value cases #116

Closed wawan93 closed 11 months ago

wawan93 commented 1 year ago

I've added some test cases in JSON for documentation purposes. Only "00000000-0000-0000-0000-000000000000" and null values are parsed without errors. Empty strings (even with omitempty tag) are parsed with the error invalid UUID length.

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

noahdietz commented 11 months ago

Empty strings (even with omitempty tag) are parsed with the error invalid UUID length.

I'm new to this project but @bormanp is this ideal? My gut says that deserializing a JSON blob that omits a UUID field into a struct that states omitempty for that same UUID field shouldn't produce an error and instead should just be Nil. If we fix this, we fix it in a separate PR of course. Even without omitempty I don't think it should be an error, just Nil.

Edit: I guess omitempty is for serialization not deserialization, so it's not a distinction for Unmarshal.