Repository navigation
fix: give every range shape its own Parse and TryParse, so minimal APIs bind it - #177
Merged
Merged
Conversation
…Is bind it A minimal-API parameter typed as one shape (Int32Range.Finite, …) found the union's inherited TryParse, which succeeded, and could not assign its result to the parameter: a valid literal bound null and the handler ran with 200, a literal of another shape too. MVC was right, through the shape's TypeConverter. Every shape of the 11 range types now has a static Parse returning the shape and TryParse(string?, IFormatProvider?, out shape), both through RangeFormat.ParseVariant/TryParseVariant, which the shapes' TypeConverter now uses as well. The records are partial so the 55 shapes' members live in one RangeVariantParsing.cs per package. The 11 '<Type> variant minimal TryParse ' candidates (#116) go; claim J38 covers the new surface; the seed variant-without-tryparse.patch removes Int32Range.Finite's TryParse and fails HostCultureProbeTests on every source and culture. Two TimeRange seeds get the partial context. Closes #116 Found-By: OT Defect-Class: JSON Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # docs/migration.md # test/oracles/candidates.json
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 #116
Stacked on #175 (base
fix/sub-microsecond-literal), which is stacked on #173 → #171.Problem
A minimal-API parameter typed as one shape, such as
Int32Range.FiniteorDateRange.UnboundedEnd, boundnullfor a valid literal and the handler answered 200, even when the parameter wasn't nullable. A literal of another shape did the same. The shapes had noTryParseof their own. The binder found the union's inheritedTryParse, which succeeded, and then couldn't assign the union-typed result to the parameter.HostCultureProbeTestsmeasured it for all 11 range types × 5 shapes × {query, nullable query, route value, form field} × 4 request cultures. MVC and JSON bodies were correct.Change
src/CodoMetis.ValueRanges/Internals/RangeFormat.cs:ParseVariant/TryParseVariantread a literal as one shape, returningFormatException/falsefor another.RangeVariantTypeConverternow usesParseVariant, so the shape check lives in one place.src/CodoMetis.ValueRanges/RangeVariantParsing.csandsrc/CodoMetis.ValueRanges.NodaTime/RangeVariantParsing.cs: every shape of the 11 range types getsstatic new TShape Parse(string, IFormatProvider?)andstatic bool TryParse(string?, IFormatProvider?, out TShape?). To keep the 110 members in one file per package, the range records and their shapes are nowpartial, which doesn't open the closed hierarchy because the constructors stay private. The span overloads stay the union's.docs/serialization.md#bind-a-range-from-configuration(claim J38 covers the new surface), adocs/migration.mdv9.x section, and changelog lines under Breaking (400 instead of 200 +null) and Added (root, core, NodaTime).test/oracles/candidates.json: the 11<Type> variant minimal TryParserows (Minimal API binds a variant-typed parameter as null for a valid literal and answers 200 #116) are removed.variant-without-tryparse.patch(new).variant-without-json-converter.patchandvariant-without-type-converter.patchget thepartialcontext line.Tests
HostCultureProbeTestsis the oracle. All 11 rows pass with the candidates removed, and they failed as "candidate fixed" before the removal.RangeParseFormatTests.ShapeParse_ReadsOnlyItsOwnShape: right shape, wrong shape (message), garbage,null, all five shapes, and the union overload still reachable through a shape's name.Int32Range.Finite.TryParse(the committed seed) fails theInt32Rangerow withanswered 200 having bound null for [-5,9]under every culture.dotnet test: every project passes, both integration suites included (Docker, postgres:17).#115 (range side)
#166 already covered it.
DecimalRange.ParseValuegoes throughDecimalLiteral.Parse(exact or refused), and every range entry point reaches it:Parse,TryParse, JSON, theTypeConverterand the EF JSON document. No otherdecimal.Parseremains on a range path insrc/, and the literal corpus probe shows no decimal rows. Nothing to change here.Value-semantics review (whole stack)
Run over #171, #173, #175 and this PR, with nothing found to fix:
timestamptz, wall clocks fortimestamp, and equal-value decimals with different scale are not inverted.TimeRange, for example) parses to empty.partialkeeps the unions closed.sub-microsecondfamily as documented, so the exact three values rest onDomainBoundaryDivergenceTestsand the S08 round-trip unit tests.🤖 Generated with Claude Code