Skip to content

Commit

Permalink
Fix date format
Browse files Browse the repository at this point in the history
  • Loading branch information
horejsek committed Nov 14, 2023
1 parent 38e0116 commit 834c455
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
=== UNRELEASED

* Fixed date format to accept only two digit months and days

=== 2.19.0 (2023-11-14)

* Added `use_formats` parameter to allow disable automatic assertions
Expand Down
2 changes: 1 addition & 1 deletion fastjsonschema/draft07.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class CodeGeneratorDraft07(CodeGeneratorDraft06):
FORMAT_REGEXS = dict(CodeGeneratorDraft06.FORMAT_REGEXS, **{
'date': r'^(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})\Z',
'date': r'^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})\Z',
'iri': r'^\w+:(\/?\/?)[^\s]+\Z',
'iri-reference': r'^(\w+:(\/?\/?))?[^#\\\s]*(#[^\\\s]*)?\Z',
'idn-email': r'^[^@]+@[^@]+\.[^@]+\Z',
Expand Down
14 changes: 14 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ def test_hostname(asserter, value, expected):
asserter({'type': 'string', 'format': 'hostname'}, value, expected)


exc = JsonSchemaValueException('data must be date', value='{data}', name='data', definition='{definition}', rule='format')
@pytest.mark.parametrize('value, expected', [
('', exc),
('bla', exc),
('2018-2-5', exc),
('2018-02-05', '2018-02-05'),
])
def test_date(asserter, value, expected):
asserter({
'$schema': 'http://json-schema.org/draft-07/schema',
'format': 'date',
}, value, expected)


exc = JsonSchemaValueException('data must be custom-format', value='{data}', name='data', definition='{definition}', rule='format')
@pytest.mark.parametrize('value,expected,custom_format', [
('', exc, r'^[ab]$'),
Expand Down

0 comments on commit 834c455

Please sign in to comment.