Repository navigation
fix: strip whitespace at either end of a quoted or escaped range bound - #73
Merged
Merged
Conversation
PostgreSQL's range_in keeps whitespace in a bound whether it is quoted, escaped or bare, and every element input function behind the seven range types strips ASCII whitespace from both ends (measured on PostgreSQL 17, recorded in #45). The parser dropped only unquoted whitespace, so [" 2026-01-01",2026-02-01) reached the strict ISO grammar and threw. ScanBound now reads the bound as range_in does and trims LiteralWhiteSpace from the result. A no-break space is still bound text, and a bound of only whitespace is still present and empty, so both still throw. The grammar contract sweep and the live parity test cover all six ASCII whitespace characters, quoted, escaped and bare, for every range type. The revert is kept as the quoted-bound-whitespace-kept seed; the quoted-empty-bound-is-infinite seed is refreshed against the new code. Closes #45 Found-By: RV Defect-Class: LIT Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 17, 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 #45
Problem
A quoted range bound with whitespace at either end threw
FormatException, but PostgreSQL reads it:I measured this on PostgreSQL 17 for
int4range,int8range,numrange,daterange(including-infinity),tsrange,tstzrangeand a customtimerange. The full table is in the issue. Every type behaves the same:range_inkeeps the whitespace in the bound, whether it's quoted, escaped or bare.The library dropped only unquoted whitespace. A quoted or escaped space reached the strict ISO grammar, so all 8 temporal range types threw on it. The numeric types already accepted it, because
int.Parseanddecimal.Parsetrim.This fails loudly and the fix only accepts more, so it fits 9.1.0.
Change
src/CodoMetis.ValueRanges/Internals/RangeFormat.cs:ScanBoundreads the bound the wayrange_indoes, then trimsLiteralWhiteSpace(the same six ASCII characters) from the result. Thesignificantbookkeeping is gone. An absent bound is still the only infinite one. The element grammar is still strict ISO 8601. The NodaTime ranges parse through the same scanner, soLocalDateRange,LocalDateTimeRange,InstantRangeandYearMonthRangechange with it. That's why the NodaTime changelog has a line too, and why I addedpackage/nodatime.docs/serialization.md#quote-a-bound: the whitespace bullet now covers quoted and escaped bounds. Two "Good to know" bullets cover ASCII-only whitespace and the behaviour before 9.1. ClaimJ33-bound-whitespace-strippedintest/oracles/claims.jsonquotes the new sentence.### Fixedline in the root, core and NodaTime changelogs.Tests
RangeLiteralGrammarContractTests(conventions) now sweeps every range type through every entry point (Parse, span,TryParse, JSON,TypeConverter,RangeSet.Parse). It reads quoted, escaped and mixed bounds with each ASCII whitespace character. It checks that a no-break or em space throws, and that a quoted or escaped whitespace-only bound throws.LiteralGrammarParityTests.BoundWhitespace_ReadsAsPostgresReadsIt(integration) sends 72 literals per type to a live PostgreSQL and compares by value. It covers 11 type pairings, with 8 whitespace characters × 9 forms each, and includes the NodaTime types.RangeParseFormatTestsandNodaTimeParseFormatTests.ScanBound. The conventions sweep then failed 192 rows (8 temporal types × 4 forms × 6 characters). The core and NodaTime repro tests failed with' 2026-01-01' is not a valid DateOnly. The live tests failed 289 rows withlibrary refused, PostgreSQL [2026-01-01,…]. That revert is now the seedtest/oracles/seeds/quoted-bound-whitespace-kept.patch. I refreshedquoted-empty-bound-is-infinite.patchagainst the new code, because the old one no longer applied.dotnet run tools/oracles.cs seeds quotedreports both seeds caught by both oracles.dotnet test, including both integration projects, passes locally.Follow-up: temporal value sets have the same refusal (
DateSet.Parse("{\" 2026-01-01\"}")), filed as #70.🤖 Generated with Claude Code