Repository navigation
fix: do not parse a date string that describes no real date - #12430
Conversation
Building a date from a month or day past its end carried the surplus into the next month, so `value = '2026-02-30'` answered with `'2026-03-02'`: the property was rewritten to a date that was never asked for, and `value-changed` fired with it. A `min` or `max` shifted the same way, silently moving the constraint. Such a string is now not parsed, which routes it into the path an unparsable value already takes: the previous value is kept, and typing one reports bad input rather than jumping to another month. `parseUTCDate` matches, so the same holds for `<vaadin-date-time-picker>`. Related to #3942 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — collected 1 finding below that could not be attached to the diff.
| Finding | |
|---|---|
An impossible i18n.referenceDate now makes getAdjustedYear throw instead of using a shifted date. |
i18n.referenceDate now makes getAdjustedYear throw instead of using a shifted date.
Set i18n.referenceDate to a well-formed but non-existent date, e.g. '2026-02-30' or '2023-02-29', then type a date with a 2-digit year such as 1/15/24. The default i18n.parseDate takes the short-year branch and runs usedReferenceDate = parseDate(this.referenceDate). parseDate now returns undefined for an impossible date (before this PR it returned a rolled-over Date like Mar 2 2026). It is passed straight into getAdjustedYear, whose first line referenceDate.getFullYear() then throws TypeError: Cannot read properties of undefined. There is no try/catch on the _onInput path, so the input handler throws on the keystroke.
The PR turns a silently-wrong reference date into a hard crash for this input class. Guard the fallback: const usedReferenceDate = parseDate(this.referenceDate) || new Date();. (A syntactically garbage referenceDate already crashed here before the PR; the newly-broken case is the well-formed-but-impossible date.)
vaadin-date-picker-mixin.js:66 · correctness · confirmed
Fixed. |
`getAdjustedYear` reads the year off the reference date, so a `referenceDate` that does not parse made typing a two-digit year throw from the input handler. A garbage one already did; an impossible one such as `2026-02-30` joined it once such a date stopped being parsed. Falling back to today is what the property documents as its default, and is already what an empty one does. Coercion of a non-string is left to throw where it always did: the parser documents a string, and an entry from a `dateMetadataProvider` is the caller that has to check its own input. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
29cc077 to
8c70708
Compare
|
|
This PR has been cherry-picked to 24.9: #13284 |
|
This PR has been cherry-picked to 24.10: #13285 |



parseDatebuilt a date from the month and day as given, and building one past the end of its month carries the surplus into the next one. So a date that does not exist was accepted as a different date. Measured onmain:value'2026-02-30''2026-03-02''2026-13-01''2027-01-01''2026-01-32''2026-02-01''2026-00-10''2025-12-10''2026-01-00''2025-12-31'The property was rewritten to a date the application never asked for, and
value-changedfired with it. A constraint shifted the same way:min = '2026-02-30'gave a minimum of 2 March, so 1 March was reported invalid.Such a string is now not parsed. That routes it into the path an unparsable value already takes in
_valueChanged— the previous value is kept — so it behaves like the non-ISO formats that are already rejected. Typing one reports bad input instead of jumping to another month, which is what<input type="date">does.parseUTCDatematches, so the same holds for<vaadin-date-time-picker>.Trade-off worth a look
A
minormaxthat does not parse is not applied at all, so an impossible one now leaves the field unconstrained where it used to constrain the wrong day. Neither is good; this one is at least the same rule that already governs every other unparsablemin. The remedy for both is the warning on an unsupported format asked for in #3942, which is not part of this change.Flow
Nothing to change on the Flow side:
value,minandmaxcome fromLocalDate.toString(), andLocalDatecannot hold a date that does not exist, so the server can never send one.i18n.parseDaterunsdate-fnsparseand returns parts only whenisValidpasses, so the parts it hands to the web component always describe a real date.correctFullYearcalls the web component's parser ondatepicker.value, which the component itself formatted, so it is always a real date.One pre-existing connector bug is worth reporting separately:
formatDatebuilds an unpadded${year}-${month + 1}-${day}and feeds it to the same parser, which does not accept a one-digit unsigned year. For a year below 10 it therefore getsundefinedand passes it todateFnsFormat. That is the same unpadded round-trip behind the years 0-9 half of #1789, and it is unaffected by this change.Related to #3942
🤖 Generated with Claude Code