Skip to content

Commit 1114177

Browse files
authored
Fix date format validator to allow non-str objects (#576)
Rejecting non-string data results in incorrect rejection of data in which `string` is one of the available types and the `date-time` format is in use. Fixes #571
1 parent ebb0214 commit 1114177

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Unreleased
99
----------
1010

1111
.. vendor-insert-here
12+
- Fix a bug in the evaluation of the ``date-time`` format on non-string data,
13+
which incorrectly rejected values for which ``string`` was one of several
14+
valid types. Thanks :user:`katylava`! (:issue:`571`)
1215

1316
- Update vendored schemas: bitbucket-pipelines, mergify, renovate (2025-06-29)
1417

src/check_jsonschema/formats/implementations/rfc3339.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
def validate(date_str: object) -> bool:
5858
"""Validate a string as a RFC3339 date-time."""
5959
if not isinstance(date_str, str):
60-
return False
60+
return True
6161
if not RFC3339_REGEX.match(date_str):
6262
return False
6363

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"some_date": null}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"some_date": {
6+
"type": ["string", "null"],
7+
"format": "date-time"
8+
}
9+
},
10+
"required": ["some_date"],
11+
"additionalProperties": false
12+
}

tests/unit/formats/test_rfc3339.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def test_simple_positive_cases(datestr):
2222
@pytest.mark.parametrize(
2323
"datestr",
2424
(
25-
object(),
2625
"2018-12-31T23:59:59",
2726
"2018-12-31T23:59:59+00:00Z",
2827
"2018-12-31 23:59:59",

0 commit comments

Comments
 (0)