Skip to content

test(format/date-time): add trailing newline as invalid#959

Open
vtushar06 wants to merge 1 commit into
json-schema-org:mainfrom
vtushar06:datetime-trailing-newline
Open

test(format/date-time): add trailing newline as invalid#959
vtushar06 wants to merge 1 commit into
json-schema-org:mainfrom
vtushar06:datetime-trailing-newline

Conversation

@vtushar06

Copy link
Copy Markdown
Contributor

Following the methodology I used for ipv4 and uuid, I read RFC 3339 section 5.6 and found the suite has no date-time test for a trailing newline.

RFC 3339 section 5.6 defines date-time = full-date "T" full-time, and every production is a fixed sequence of digits and literals ending at the time-offset - the grammar emits no line feed, so nothing may follow the offset. A single trailing \n is therefore invalid. The suite tests a trailing space (Z ) and trailing content (Z extra), both of which the reference validator rejects; it does not test the newline, which the reference validator accepts.

Changes

  • Added 1 test case across draft3, draft4, draft6, draft7, draft2019-09, draft2020-12, and v1.
  • 1985-04-12T23:20:50Z\n - a valid date-time followed by a single line feed - invalid.

Ecosystem Impact

  1. python-jsonschema 4.25.1: FAILS (accepts it). Its date-time check delegates to rfc3339-validator, which builds RFC3339_REGEX + "$" and calls re.match; Python's $ matches immediately before a single trailing \n, so the line feed is never seen. Z and Z extra get rejected, but Z\n slips through.
  2. ajv-formats 3.0.1 (full and fast): PASSES (rejects it). JavaScript $ without the m flag matches only at the very end of the string, so the trailing \n is not consumed.
  3. sourcemeta/core is_rfc3339_datetime: PASSES (rejects it) - it requires the whole string to parse.
  4. Corroboration: jsonschema-rs 0.45.0, boon 0.6.1, santhosh-tekuri/jsonschema v6.0.2, and @hyperjump/json-schema 1.17.6 (four more JSON Schema validators, each with its own RFC 3339 parser) all reject it - so python-jsonschema is the lone outlier.

RFC References

Reproduction and the date-time cross-implementation matrix are in my evidence repo: https://github.com/vtushar06/JSON-Schema-format-test-Evidence/blob/main/date-time.md

Related: #965

Copilot AI review requested due to automatic review settings July 1, 2026 13:46
@vtushar06 vtushar06 requested a review from a team as a code owner July 1, 2026 13:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the JSON Schema Test Suite’s date-time format coverage by adding a negative test case for RFC 3339 date-time strings that include a single trailing line feed (\n), ensuring validators reject input with any trailing characters after the time offset.

Changes:

  • Added an invalid date-time format test for a trailing newline: "1985-04-12T23:20:50Z\n" (expected valid: false).
  • Applied the same test addition consistently across draft3/draft4/draft6/draft7/draft2019-09/draft2020-12 optional suites and the v1 suite.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/v1/format/date-time.json Adds an invalid trailing-newline date-time test case to the v1 suite.
tests/draft7/optional/format/date-time.json Adds the same invalid trailing-newline date-time test case for draft7 optional format tests.
tests/draft6/optional/format/date-time.json Adds the same invalid trailing-newline date-time test case for draft6 optional format tests.
tests/draft4/optional/format/date-time.json Adds the same invalid trailing-newline date-time test case for draft4 optional format tests.
tests/draft3/optional/format/date-time.json Adds the same invalid trailing-newline date-time test case for draft3 optional format tests.
tests/draft2020-12/optional/format/date-time.json Adds the same invalid trailing-newline date-time test case for draft2020-12 optional format tests.
tests/draft2019-09/optional/format/date-time.json Adds the same invalid trailing-newline date-time test case for draft2019-09 optional format tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jviotti jviotti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a good example of how weird regexes can get across languages, confusing users of pattern, etc

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.

3 participants