Skip to content

null: fix NullUUID.Scan returning Valid=true for empty string/bytes#216

Open
c-tonneslan wants to merge 1 commit into
google:masterfrom
c-tonneslan:fix/null-uuid-scan-empty-string
Open

null: fix NullUUID.Scan returning Valid=true for empty string/bytes#216
c-tonneslan wants to merge 1 commit into
google:masterfrom
c-tonneslan:fix/null-uuid-scan-empty-string

Conversation

@c-tonneslan
Copy link
Copy Markdown

Fixes #109.

UUID.Scan treats an empty string and an empty []byte as a null UUID, returning nil without actually parsing anything. But NullUUID.Scan didn't check for this case — it just delegated to UUID.Scan, saw the nil error, and set Valid = true. So callers would get back a non-null NullUUID wrapping the zero UUID value, which is incorrect.

The fix mirrors the empty-input check that already exists in UUID.Scan, so empty string/bytes are treated the same as a nil value: Valid = false, UUID = uuid.Nil.

Added a regression test for both the string and []byte cases.

UUID.Scan treats empty string and empty []byte as a null UUID, returning
nil without parsing. NullUUID.Scan saw that nil error and set Valid=true,
so callers would get a non-null NullUUID with the zero UUID value.

Fix by checking for empty string/bytes before delegating to UUID.Scan,
mirroring the same logic, so Valid=false is set for empty input just as
it is for an actual nil value.

Fixes google#109
@c-tonneslan c-tonneslan requested a review from a team as a code owner May 12, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullUUID Scan method returns valid true on empty string

1 participant