Repository navigation
fix: refuse an inverted range literal, as PostgreSQL's range_in does - #171
Merged
Merged
Conversation
A finite literal whose lower bound is greater than its upper bound
went through CreateFinite, whose rule for computed bounds makes it
empty. So [5,1) parsed as empty on every entry point (Parse, TryParse,
JSON, TypeConverter, the EF JSON document reader) and an inverted
element vanished from a multirange literal, where PostgreSQL refuses the
text. RangeFormat now compares the bounds as written, before a discrete
type closes them, and throws FormatException. Equal bounds that are not
both inclusive stay empty, as on the server, and CreateFinite keeps its
rule.
Removes the 20 '{type} inverted ' candidates (#114), adds claim J35
and the seed inverted-literal-reads-empty.patch, inverted literals in
LiteralGrammarParityTests, and fills the core package changelog's
10.0.0 section, which still said "No change".
Closes #114
Found-By: OT
Defect-Class: LIT
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 18, 2026
…teral # Conflicts: # src/CodoMetis.ValueRanges/CHANGELOG.md
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 #114
Problem
A range literal whose lower bound is greater than its upper bound parsed as
emptyon every entry point, where PostgreSQL'srange_inrejects the text (range lower bound must be less than or equal to range upper bound).RangeFormat.Parsehanded the two parsed bounds toCreateFinite, which applies the factory's rule for computed bounds. SoInt32Range.Parse("[5,1)")wasempty,TryParsereturnedtrue, JSON and theTypeConverterreadempty, a minimal API answered 200 with an empty range, andRangeSet.Parse("{[5,1),[7,9]}")was{[7,9]}: the inverted element vanished. A swapped period in a query string or a JSON body silently matched nothing.Change
src/CodoMetis.ValueRanges/Internals/RangeFormat.cs: a finite literal goes throughFinite, which compares the bounds as written (before a discrete type closes them) and throwsFormatExceptionwhen lower > upper. Every entry point reads the literal throughRangeFormat.Parse, soTryParsereturnsfalse, JSON throwsJsonException, theTypeConverterthrows, andRangeSet.Parsethrows. Equal bounds that aren't both inclusive ([5,5),(5,5)) and closing bounds ((1,2)over integers) stayempty, as on the server.CreateFinitekeeps its documented rule (inverted →Empty), as the issue asks.docs/serialization.md#parse-a-literalstates the rule (new claim J35 quotes it),docs/ranges.mdpoints from the factory rule to it,docs/migration.mdhas the v9.x entry, and the root changelog has the Breaking line.src/CodoMetis.ValueRanges/CHANGELOG.md: its 10.0.0 section said "No change in this package" although the five value-set fixes merged today (fix: read GuidSet elements with PostgreSQL's uuid_in grammar #162–fix: read decimal text exactly or refuse it #166) are core changes. It now carries those five lines and this one, copied from the root.test/oracles/candidates.json: the 20{type} invertedrows (An inverted range literal parses as empty on every entry point; PostgreSQL rejects it #114) are removed. They failed as "candidate fixed" with the fix in place.test/oracles/seeds/inverted-literal-reads-empty.patch: the fix reverted, namingLiteralCorpusProbeTestsandLiteralGrammarParityTests.Tests
RangeParseFormatTests: inverted literals throughParse(string and span),TryParse(string and span), JSON (union andFinite), theTypeConverterandRangeSet.TryParse; temporal ([infinity,2026-01-01),(2026-01-01,-infinity]) and continuous inverted literals; equal and closing bounds stayempty;CreateFinite(5, 1)staysEmpty.LiteralGrammarParityTests(integration):[5,1),(5,1],[2,1), the equal-bound forms, inverteddaterangeliterals and{[5,1),[7,9]}are asked of PostgreSQL 17.LiteralCorpusProbeTests(integration): theinvertedfamily passes for all 10 range and 10 multirange types.RangeParseFormatTestscases fail,LiteralGrammarParityTestsreportsint4range [5,1): library empty, PostgreSQL refusedandint4multirange {[5,1),[7,9]}: library {[7,9]}, and the corpus probe reportslibrary empty, PostgreSQL refusesfor every type. That revert is the committed seed.dotnet test: every project passes, both integration suites included (Docker, postgres:17).🤖 Generated with Claude Code