Skip to content

fix: refuse a NUL character in a string set element - #163

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/string-set-nul
Oct 18, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/string-set-nul

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #133

Stacked on #162 (fix/uuid-in-grammar); the diff against main includes that PR until it merges.

Problem

StringSet.Parse("{a\0b}") and StringSet.From(["a\0b"]) accepted the element, and so did StringSet<T> through its element's Parse. PostgreSQL text cannot hold U+0000 (chr(0) is "null character not permitted"; a text[] parameter holding one is "invalid byte sequence for encoding UTF8: 0x00"), so a consumer built the set in memory and got the failure from the server at save time, away from where the text came in.

Change

  • src/CodoMetis.ValueRanges/Internals/TextElement.cs (new): the rule, once. Require for a value being stored (ArgumentException, as a null element is) and RequireParsable for text being parsed (FormatException, as any refused element text is).
  • StringSet: From (both overloads), NormalizeElement (so Contains, Add and Remove refuse the probe From refuses) and ParseValue (Parse, TryParse, the TypeConverter, the EF JSON document reader) apply it; JSON reaches From. StringSet<T>: the same paths, on the element's text form, which is what the column holds.
  • test/oracles/candidates.json: the two LiteralCorpusProbeTests rows for StringSet accepts a NUL character, which PostgreSQL text cannot hold #133 are removed. test/oracles/clone-waivers.json: four entries for the members only the string families now have (NormalizeElement on both, RequireText on the arity).
  • docs/value-sets.md#parse-and-print-literals: a bullet, with claim S18-nul-refused in claims.json. CHANGELOG.md 10.0.0 Breaking row; docs/migration.md "Keep NUL out of string elements".

Tests

  • SetParseFormatTests: StringElement_WithANulCharacter_IsRefusedByTheLiteral (bare, quoted, escaped, alone; Parse, TryParse, and StringSet<TestPermission>), StringElement_WithANulCharacter_IsRefusedAtConstruction (From both overloads, Add, Contains, JSON; the arity through its element), StringElement_EveryOtherCharacter_IsText (a control character, a no-break space, é stay text).
  • LiteralCorpusProbeTests (postgres:17): the StringSet NUL and StringSet<TextKey> NUL families now agree with the server.
  • Fix reverted (StringSet.cs from the parent commit, TextElement.cs deleted, tests kept): all five new test rows fail. Restored afterwards.
  • Full runs: core 949, conventions 324, EF translation 245, AspNetCore 84, NodaTime 196, integration (LiteralCorpusProbeTests, SetIntegrationTests, WrapperArityIntegrationTests, SetOperatorParityTests) 77 — green. dotnet run tools/oracles.cs clones: 66 waived, 0 unwaived, 0 stale.

🤖 Generated with Claude Code

StringSet.Parse("{a\0b}") and StringSet.From(["a\0b"]) accepted the
element, and so did StringSet<T> through its element's Parse. PostgreSQL
text cannot hold U+0000 (chr(0) is "null character not permitted"; a
parameter holding one is "invalid byte sequence for encoding UTF8"), so
the set was built in memory and failed at save time, away from where
the text came in. Measured on PostgreSQL 17.

TextElement holds the rule once. StringSet applies it in From (both
overloads), in NormalizeElement (so Contains, Add and Remove refuse the
probe From refuses) and in ParseValue (Parse, TryParse, the
TypeConverter, the EF JSON document); JSON reaches From. StringSet<T>
applies it to the element's text form on the same paths. From and Add
throw ArgumentException, as a null element does; a parse throws
FormatException, as any refused element text does. Every other
character stays text, as textin keeps it.

Closes #133

Found-By: OT
Defect-Class: LIT

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working breaking Changes an answer or a signature — needs a major found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/value-sets Value set families and wrapper arities area/literals Parse, TryParse and formatting package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 18, 2026
Base automatically changed from fix/uuid-in-grammar to main October 18, 2026 13:10
@CaffeinatedCoder CaffeinatedCoder removed the stacked Base is another open PR; merge in order, CI does not run until it targets main label Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 7d48403 into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/string-set-nul branch October 18, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/literals Parse, TryParse and formatting area/value-sets Value set families and wrapper arities breaking Changes an answer or a signature — needs a major bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StringSet accepts a NUL character, which PostgreSQL text cannot hold

1 participant