Skip to content

fix(forms): validate date and datetime-local field submissions - #684

Merged
jimhoyd merged 1 commit into
mainfrom
fix/forms-date-validation
Sep 24, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
fix/forms-date-validation

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #682

What changed

  • packages/forms/src/forms.ts: admission() now has date and datetime-local branches, placed alongside the email branch and matching its message style:
    • date: YYYY-MM-DD (HTML "valid date string"). Error: must be a valid date.
    • datetime-local: YYYY-MM-DDTHH:MM, with optional :SS and optional .f/.ff/.fff fractional seconds (HTML "valid normalized local date and time string" plus the non-normalized seconds forms a browser can send). There is no timezone offset, and the separator must be T. Error: must be a valid local date and time.
    • Impossible calendar values are refused, with leap years handled: 2026-02-30, 2027-02-29, 1900-02-29, month 00/13, day 00, April 31, year 0000, hour 24, minute 60, second 60.
  • Tests (packages/forms/test/forms.test.ts): the shared contact flow gains optional visit (date) and callback (datetime-local) fields. A new test covers valid dates (including leap days), malformed and impossible dates, datetime-local values with and without seconds and fractions, invalid datetime-local values (space separator, Z/offset, 4 fractional digits, out-of-range times), and empty optional fields still being admitted. With the src change reverted, the new test fails.
  • README validation list and package CHANGELOG (## Unreleased) updated. No page in docs/ lists per-type validations, since docs/EXTENSIONS.md links to the package README.

Deliberate limits

Verification

  • npm run typecheck: clean
  • forms package tests: 15/15 pass
  • npm run verify: exit 0 (root 781/781, then every workspace verify, the add-on manifest check, package audit and the add-on integration tests)

CI passing is not an independent security review.

🤖 Generated with Claude Code

admission() checked email and number formats but accepted any string for
type: date and type: datetime-local. Validate the formats browsers submit
(HTML valid date string / valid normalized local date and time string):
YYYY-MM-DD, and YYYY-MM-DDTHH:MM with optional :SS and up to three
fractional-second digits, no timezone offset. Impossible calendar values
(2026-02-30, month 13, hour 24, year 0000) are refused with a 422 field
error. No min/max date bounds (#528).

Fixes #682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd merged commit ceb7e7a into main Sep 24, 2026
16 checks passed
@jimhoyd
jimhoyd deleted the fix/forms-date-validation branch September 24, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: forms accepts any string for date and datetime-local fields

1 participant