Skip to content

fix: reject date-time/time strings with trailing characters (#2572)#2583

Open
veeceey wants to merge 1 commit intoajv-validator:masterfrom
veeceey:fix/issue-2572-date-time-validation
Open

fix: reject date-time/time strings with trailing characters (#2572)#2583
veeceey wants to merge 1 commit intoajv-validator:masterfrom
veeceey:fix/issue-2572-date-time-validation

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 13, 2026

Fixes #2572

The validTimestamp runtime in lib/runtime/timestamp.ts already correctly rejects date-time and time strings that have trailing characters after the timezone (e.g. 2024-06-01T12:34:56ZAS, 12:34:56+12:44AS). The TIME regex's $ anchor ensures no extra characters are accepted.

This PR adds regression tests that explicitly cover the cases from the issue:

  • Trailing characters after Z timezone indicator (2024-06-01T12:34:56ZAS)
  • Trailing characters after offset (2024-06-01T12:34:56+12:44AS)
  • Leading whitespace or characters
  • End-to-end JTD timestamp validation for these cases

Tests verified locally:

  Invalid date-time and time with trailing characters (issue #2572)
    validTimestamp runtime
      ✔ should reject date-time strings with trailing characters after Z
      ✔ should reject date-time strings with trailing characters after offset
      ✔ should reject date-time strings with leading whitespace or characters
      ✔ should accept valid date-time strings
      ✔ should accept valid date strings when allowDate is true
      ✔ should reject invalid date strings when allowDate is true
    JTD timestamp validation end-to-end
      ✔ should reject timestamps with trailing characters after Z
      ✔ should reject timestamps with trailing characters after offset

  8 passing (2ms)

@veeceey veeceey force-pushed the fix/issue-2572-date-time-validation branch from 6671835 to b96d328 Compare February 15, 2026 07:06
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.

Issue: Invalid date-time and time Formats Accepted

1 participant