Conversation
The UUID type guard and deserializer only checked the length and the dash positions, so any 36-character string with dashes in the right places passed, including ones with non-hex characters. They now match RFC 9562: hex digits, version 1 to 8, the RFC variant, or the Nil and Max UUIDs.
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.
Summary of changes
The
UUIDtype guard and deserializer only check the length and the positions of the dashes:`${v}.length === 36 && ${v}[23] === '-' && ${v}[18] === '-' && ${v}[13] === '-' && ${v}[8] === '-'`So any 36-character string with dashes in those places counts as a UUID, including strings that are not hex at all:
Both checks now use one pattern that follows RFC 9562:
8-4-4-4-12layout, case-insensitive1to88,9,aorb00000000-0000-0000-0000-000000000000) or the Max UUID (ffffffff-ffff-ffff-ffff-ffffffffffff)UUIDs produced by
uuid()(v4) still pass, as does any UUID from another RFC 9562 version (v1, v6, v7, …).Changes:
packages/type/src/serializer.ts: a module-leveluuidPattern, passed into the generated code withstate.setContext, used by both theisUUIDTypedeserializer decorator and the type guard decorator. The error message staysNot a UUID.packages/type/tests/validation.spec.ts: aUUIDtest coveringis,validateanddeserializewith v1, v4, v7, v8, uppercase, Nil and Max as valid, and non-hex, version0/f, variant0/cand a near-Nil value as invalid. Against the previous check, the invalid cases pass, so the test fails.Verification:
packages/typeruns 48 suites and 1854 tests. The only failures are the same 9 intests/compiler.spec.tsthat also fail onmasterin my environment (Windows). Every UUID-shaped literal in the repository's sources and tests already satisfies the new pattern.This is stricter than before, so strings that only had the right length and dashes are now rejected by
is<UUID>,validate<UUID>and deserialization.Relinquishment of Rights
Please mark following checkbox to confirm that you relinquish all rights of your changes: