Add uuid7 validation tag - #1614
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
Adds a built-in uuid7 tag validating version 7 UUIDs (RFC 9562), mirroring the existing uuid3/uuid4/uuid5 validators. Includes regex, validation function, registration, docs (doc.go + README) and tests. Fixes go-playground#1595
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What this PR does / why we need it:
Adds a built-in
uuid7validation tag for version 7 UUIDs (RFC 9562).The library already validates UUID versions 3, 4 and 5, but there's no tag
for v7. UUIDv7 has become common as a time-ordered, index-friendly primary
key, so it's a natural addition to the existing set.
Changes, following the exact shape of the existing
uuid5support:regexes.go: adduUID7RegexString/uUID7Regex. Same pattern as v4/v5with the version nibble pinned to
7and the RFC 4122/9562 variant nibble[89ab].baked_in.go: addisUUID7and register theuuid7tag.doc.goandREADME.md: document the new tag.Like
uuid4/uuid5,uuid7accepts lowercase hex only. I left acase-insensitive
uuid7_rfc4122-style variant out of this PR to keep itfocused and because the right name for it (given v7 is defined in RFC 9562,
not 4122) is a call I'd rather leave to you — happy to add it in a follow-up.
Which issue(s) this PR fixes:
Fixes #1595
Testing
Added
TestUUID7Validationmirroring the existing UUID tests: empty input,garbage prefix, wrong-version UUIDs (v3/v4), an invalid variant nibble, an
uppercase value (rejected), and two valid v7 values.
go test ./...passes;go vetis clean.Release Notes