Repository navigation
fix: refuse a NUL character in a string set element - #163
Merged
Merged
Conversation
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]>
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 #133
Stacked on #162 (
fix/uuid-in-grammar); the diff againstmainincludes that PR until it merges.Problem
StringSet.Parse("{a\0b}")andStringSet.From(["a\0b"])accepted the element, and so didStringSet<T>through its element'sParse. PostgreSQLtextcannot hold U+0000 (chr(0)is "null character not permitted"; atext[]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.Requirefor a value being stored (ArgumentException, as a null element is) andRequireParsablefor text being parsed (FormatException, as any refused element text is).StringSet:From(both overloads),NormalizeElement(soContains,AddandRemoverefuse the probeFromrefuses) andParseValue(Parse,TryParse, theTypeConverter, the EF JSON document reader) apply it; JSON reachesFrom.StringSet<T>: the same paths, on the element's text form, which is what the column holds.test/oracles/candidates.json: the twoLiteralCorpusProbeTestsrows 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 (NormalizeElementon both,RequireTexton the arity).docs/value-sets.md#parse-and-print-literals: a bullet, with claimS18-nul-refusedinclaims.json.CHANGELOG.md10.0.0 Breaking row;docs/migration.md"Keep NUL out of string elements".Tests
SetParseFormatTests:StringElement_WithANulCharacter_IsRefusedByTheLiteral(bare, quoted, escaped, alone;Parse,TryParse, andStringSet<TestPermission>),StringElement_WithANulCharacter_IsRefusedAtConstruction(Fromboth overloads,Add,Contains, JSON; the arity through its element),StringElement_EveryOtherCharacter_IsText(a control character, a no-break space,éstay text).LiteralCorpusProbeTests(postgres:17): theStringSet NULandStringSet<TextKey> NULfamilies now agree with the server.StringSet.csfrom the parent commit,TextElement.csdeleted, tests kept): all five new test rows fail. Restored afterwards.dotnet run tools/oracles.cs clones: 66 waived, 0 unwaived, 0 stale.🤖 Generated with Claude Code