Skip to content

Escape one character trimmed date formats - #1858

Merged
SimonCropp merged 1 commit into
mainfrom
fix-trimmed-fraction-format
Aug 17, 2026
Merged

Escape one character trimmed date formats#1858
SimonCropp merged 1 commit into
mainfrom
fix-trimmed-fraction-format

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

DateMatchers.BuildForFormats builds a second scrubber for the trimmed format when a format ends in an upper case fraction, since those render as empty when the fraction is zero. TryGetFormatWithUpperMillisecondsTrimmed handed back the trimmed string raw, and a one character format string is read as a standard format specifier rather than the custom one it was written as:

  • ScrubInlineDateTimes("s.F") trimmed to "s", which expands to the culture's sortable pattern — so the second scrubber scrubbed every full sortable date-time in the output.
  • ScrubInlineDateTimes("H.F") trimmed to "H", which is not a standard specifier at all — Invalid format: H at registration, after the format had already passed the up-front validation.

Now % escapes the trimmed format when one character is left, which is what forces it to be read as a custom specifier, and no second scrubber is built when trimming leaves nothing (".F").

Tests in the new TrimmedFractionTests cover all three cases; all three fail on main. ApplyScrubbersTests (114), Verify.Tests (1299) and StaticSettingsTests pass.

Unrelated observation while in here: the trim only recognises .F through .FFFF, so .FFFFF through .FFFFFFF never get a trimmed scrubber. Left alone since TryParseExact treats the fraction (and its period) as optional anyway, which makes the second scrubber look redundant rather than missing — worth a separate look at whether it earns its keep at all.

Formats ending in an upper case fraction get a second scrubber built for the
trimmed format, but a one character format string is a standard format specifier
rather than the custom one it was written as. So ScrubInlineDateTimes("s.F")
trimmed to "s", the sortable pattern, and scrubbed every full sortable date-time
in the output, while "H.F" trimmed to "H" and threw "Invalid format: H" at
registration despite passing the up-front validation.

The trimmed format is now escaped with `%` when a single character is left, and
no second scrubber is built when nothing is left at all.
@SimonCropp SimonCropp added this to the 32.0.0 milestone Aug 17, 2026
@SimonCropp
SimonCropp merged commit 724341b into main Aug 17, 2026
7 checks passed
@SimonCropp
SimonCropp deleted the fix-trimmed-fraction-format branch August 17, 2026 12:26
This was referenced Aug 26, 2026
This was referenced Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant