Skip to content

fix: strip whitespace at either end of a quoted or escaped temporal set element - #81

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/value-set-element-whitespace
Oct 17, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/value-set-element-whitespace

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #70

Problem

A date or time value set threw on a quoted or escaped element with whitespace at either end, but PostgreSQL reads it:

DateSet.Parse("{\" 2026-01-01\"}", null); // FormatException
SELECT '{" 2026-01-01"}'::date[]; -- {2026-01-01}

I measured this on PostgreSQL 17 for every element type a set family maps to. The full table is in the issue. array_in drops whitespace around a bare element itself, and hands quoted or escaped whitespace to the element's input function:

Input function Quoted or escaped ASCII whitespace Library before
int2in, int4in, int8in, numeric_in stripped stripped already (int.Parse, decimal.Parse)
date_in, timestamp_in, timestamptz_in, time_in stripped threw: all 9 temporal families (this issue)
textin kept kept
uuid_in rejected accepted: filed as #78 for 10.0.0

U+00A0, U+2003 and an element of only whitespace are rejected everywhere except textin.

This fails loudly and the fix only accepts more, so it fits 9.1.0.

Change

  • LiteralWhiteSpace.TrimAsInputFunction: one helper, documented with the measurements, that trims the same six ASCII characters (space, tab, LF, CR, VT, FF).
  • ParseValue of each temporal family calls that helper before the strict ISO grammar. That's 18 call sites: DateSet, DateTimeSet, DateTimeOffsetSet and TimeSet with their wrapper arities, and LocalDateSet, LocalDateTimeSet, InstantSet, LocalTimeSet and YearMonthSet with theirs. Parse, TryParse, the TypeConverter and the JSON element path all go through ParseValue. The element grammar itself is unchanged.
  • The trim deliberately stays out of the shared SetFormat parser, because that would strip a text[] element's own spaces. A seed shows the tests catch that.
  • docs/value-sets.md#parse-and-print-literals gets two new "Good to know" bullets, after the ones claim S12 quotes. New claim S16 quotes them.
  • Changelogs: one ### Fixed line each in the root, core and NodaTime changelogs.

Tests

  • SetElementWhiteSpaceContractTests (conventions, new oracle in oracles.json) sweeps all 30 discovered set types through Parse, TryParse, the TypeConverter and, for temporal sets, JSON. It checks each one against its input function's measured behaviour: strips, keeps or rejects. A new element type with no measured behaviour fails by name. The GuidSet rows are registered in candidates.json against GuidSet accepts whitespace inside an element that PostgreSQL's uuid_in rejects #78.
  • LiteralGrammarParityTests.ElementWhitespace_ReadsAsPostgresReadsIt (integration) covers 15 array type and family pairs against a live PostgreSQL, with 8 whitespace characters × 9 forms each. It reads text[] with unnest: reparsing the server's array output with the parser under test hid a dropped space on both sides, and the second seed showed that before I changed it. The uuid[] rows are a candidate against GuidSet accepts whitespace inside an element that PostgreSQL's uuid_in rejects #78.
  • Unit tests: the temporal repros, a test that StringSet keeps its spaces (SetParseFormatTests), and a NodaTime repro (NodaTimeSetTests).
  • Revert proof, kept as two seeds:
    • temporal-set-element-whitespace-kept.patch is this fix reverted. The core and NodaTime repro tests fail, the sweep fails with DateSet: Parse rejected …, and the parity test fails with date[] DateSet {" 2026-01-01"}: library refused, PostgreSQL {2026-01-01}.
    • set-element-whitespace-trimmed-for-text.patch moves the trim into the shared parser for every family. The StringSet unit test fails, the sweep fails with StringSet: Parse read {" beta "} as {beta}, and the parity test fails with text[] StringSet {" ab"}: library {ab}, PostgreSQL {" ab"}.
    • dotnet run tools/oracles.cs seeds element-whitespace reports every (seed, oracle) pair caught.
  • Full dotnet test, including both integration projects, passes locally.

🤖 Generated with Claude Code

…et element

array_in hands quoted and escaped whitespace to the element's input
function. date_in, timestamp_in, timestamptz_in and time_in strip space,
tab, LF, CR, VT and FF from both ends; textin keeps them; uuid_in rejects
them (measured on PostgreSQL 17, recorded in #70). The temporal families
handed the whitespace to the strict ISO grammar, so {" 2026-01-01"} threw.

Each temporal family's ParseValue, closed and wrapper arity, core and
NodaTime, now trims through LiteralWhiteSpace.TrimAsInputFunction. The
trim stays out of the shared array parser, which would strip a text[]
element's own spaces. Parse, TryParse, the TypeConverter and the JSON
element path all go through ParseValue. The numeric families already
trimmed exactly these characters through the BCL number parsers.

SetElementWhiteSpaceContractTests sweeps every discovered set type
against the measured behaviour of its input function, and a live parity
test asks PostgreSQL for the same literals, reading text[] element by
element so a dropped space cannot hide on both sides. GuidSet accepting
whitespace uuid_in rejects is registered as a candidate against #78
(10.0.0). Two seeds: the revert of this fix, and a trim in the shared
parser for every family.

Closes #70

Found-By: RV
Defect-Class: LIT
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 bug Something isn't working package/core Affects CodoMetis.ValueRanges package/nodatime Affects CodoMetis.ValueRanges.NodaTime severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quoted value set element with surrounding whitespace is refused for temporal sets; PostgreSQL accepts it

1 participant