Repository navigation
fix: read GuidSet elements with PostgreSQL's uuid_in grammar - #162
Merged
Merged
Conversation
GuidSet.ParseValue called Guid.Parse, which reads the N, D, B, P and X
formats and trims every Unicode whitespace, while uuid_in reads 32 hex
digits with a hyphen allowed after any group of four, optionally in
braces, and nothing else. So {(6f9619ff-…)} and {" 6f9619ff-…"} parsed
in memory and failed on the server as a literal, and {6f96-19ff-…},
which the server reads, threw. GuidSet<T> handed the raw text to the
element's Parse — Guid.Parse again for a generated wrapper — and the EF
bridge for GuidSet<> called Guid.Parse directly, so the grammar had
three sites.
UuidLiteral is the one grammar now: GuidSet.ParseValue reads it,
GuidSet<T>.ParseValue reads it first and hands the element the D form,
as the numeric arities do, and the bridge goes through
GuidSet.ParseValue. Measured on PostgreSQL 17 (string_to_uuid in
uuid.c). The whitespace row of SetWrapperParityTests under #141 is gone
with it, since the wrapper's JSON element reader now refuses the padded
uuid as the primitive does; the rest of #141 is the numeric arities.
Closes #78
Closes #129
Found-By: OT
Defect-Class: LIT
Co-Authored-By: Claude Fable 5.1 <[email protected]>
This was referenced Oct 18, 2026
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.
Closes #78
Closes #129
Problem
GuidSet.ParseValuecalledGuid.Parse, which reads theN,D,B,PandXformats and trims every Unicode whitespace. PostgreSQL'suuid_inreads 32 hex digits with a hyphen allowed after any group of four, optionally in braces, and nothing else. So a consumer saw:GuidSet.Parse("{(6f9619ff-8b86-d011-b42d-00c04fc964ff)}")andGuidSet.Parse("{\" 6f9619ff-…\"}")parse in memory, then fail on the server as a literal (invalid input syntax for type uuid).GuidSet.Parse("{6f96-19ff-8b86-d011-b42d-00c0-4fc9-64ff}")throwFormatException, where the server reads it.The same grammar sat at three sites:
GuidSet.ParseValue,GuidSet<T>.ParseValue(which handed the raw text to the element'sParse,Guid.Parseagain for a generated wrapper) and the EF bridge forGuidSet<>, which calledGuid.Parsedirectly (the clone sweep's waiver named it as #129's third site).Change
src/CodoMetis.ValueRanges/Internals/UuidLiteral.cs(new):uuid_in's grammar (string_to_uuidinuuid.c, measured on PostgreSQL 17): optional braces, 32 ASCII hex digits, a hyphen allowed after any group of four except the last, nothing else. Builds theGuidfrom the bytes big-endian, soD,N, braces and hyphen groups are one value.GuidSet.ParseValuereads it.GuidSet<T>.ParseValuereads it first and hands the element theDform, as the numeric arities hand theirs the primitive's invariant text. TheGuidSet<>bridge inSetTypeRegistrygoes throughGuidSet.ParseValue.test/oracles/candidates.json: the nine rows for GuidSet accepts whitespace inside an element that PostgreSQL's uuid_in rejects #78 and GuidSet reads Guid.Parse's grammar, not uuid_in's: accepts (…), refuses hyphen groups #129 are removed, and theGuidSet JSON read ["row of Wrapper set arities read JSON element tokens their primitive set refuses (quoted, padded, signed numbers; braced and unhyphenated Guids) #141 with them: the wrapper's JSON element reader now refuses a padded uuid as the primitive does, so that sweep no longer disagrees there. Wrapper set arities read JSON element tokens their primitive set refuses (quoted, padded, signed numbers; braced and unhyphenated Guids) #141 keeps the numeric rows.test/oracles/clone-waivers.json: the bridge waiver is gone (the siblings agree now), theGuidSet.ParseValuereason names the grammar, andGuidSet<T>.ParseValue/StringSet<T>.ParseValueget a waiver each (the Guid arity names theDformat becauseGuidhas noToString(IFormatProvider); the string arity's element sees the raw text becausetextinapplies no grammar, and it was never a lone body until the Guid arity stopped sharing its shape).docs/value-sets.md#parse-and-print-literals: two bullets (the grammar, and what 9.x read), with claimS17-uuid-in-grammarinclaims.jsonheld bySetParseFormatTests,SetElementWhiteSpaceContractTestsandLiteralCorpusProbeTests.CHANGELOG.md: the 10.0.0 intro line and the first### Breakingrow.docs/migration.md: the "Migration from v9.x" section with "Read UUIDs as PostgreSQL reads them".Tests
SetParseFormatTests:GuidElement_ReadsEverySpellingUuidInReads(7 spellings,GuidSetandGuidSet<TestId>),GuidElement_RefusesWhatUuidInRefuses(12 texts:P,X, whitespace at either end including a no-break space, a hyphen after two digits or after the last group, an unclosed brace, 31 and 33 digits,urn:uuid:, empty),GuidElement_WritesTheDForm.SetElementWhiteSpaceContractTestsandLiteralGrammarParityTestsnow hold their Guid rows;LiteralCorpusProbeTests(postgres:17 via Testcontainers) passes onGuidSetandGuidSet<TenantId>for thewhitespace,parenthesesandhyphen groupsfamilies.GuidSet.cs,SetTypeRegistry.cs,LiteralWhiteSpace.csfrom the parent commit,UuidLiteral.csdeleted, tests kept): 15 rows ofGuidElement_*fail, andSetElementWhiteSpaceContractTestsreportsGuidSet: accepts whitespace uuid_in rejectsthrough Parse, TryParse and the TypeConverter. Restored afterwards.dotnet run tools/oracles.cs clones: 62 waived, 0 unwaived, 0 stale.🤖 Generated with Claude Code