Skip to content

Commit 834c455

Browse files
committed
Fix date format
1 parent 38e0116 commit 834c455

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
=== UNRELEASED
2+
3+
* Fixed date format to accept only two digit months and days
4+
15
=== 2.19.0 (2023-11-14)
26

37
* Added `use_formats` parameter to allow disable automatic assertions

fastjsonschema/draft07.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class CodeGeneratorDraft07(CodeGeneratorDraft06):
55
FORMAT_REGEXS = dict(CodeGeneratorDraft06.FORMAT_REGEXS, **{
6-
'date': r'^(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})\Z',
6+
'date': r'^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})\Z',
77
'iri': r'^\w+:(\/?\/?)[^\s]+\Z',
88
'iri-reference': r'^(\w+:(\/?\/?))?[^#\\\s]*(#[^\\\s]*)?\Z',
99
'idn-email': r'^[^@]+@[^@]+\.[^@]+\Z',

tests/test_format.py

+14
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ def test_hostname(asserter, value, expected):
3737
asserter({'type': 'string', 'format': 'hostname'}, value, expected)
3838

3939

40+
exc = JsonSchemaValueException('data must be date', value='{data}', name='data', definition='{definition}', rule='format')
41+
@pytest.mark.parametrize('value, expected', [
42+
('', exc),
43+
('bla', exc),
44+
('2018-2-5', exc),
45+
('2018-02-05', '2018-02-05'),
46+
])
47+
def test_date(asserter, value, expected):
48+
asserter({
49+
'$schema': 'http://json-schema.org/draft-07/schema',
50+
'format': 'date',
51+
}, value, expected)
52+
53+
4054
exc = JsonSchemaValueException('data must be custom-format', value='{data}', name='data', definition='{definition}', rule='format')
4155
@pytest.mark.parametrize('value,expected,custom_format', [
4256
('', exc, r'^[ab]$'),

0 commit comments

Comments
 (0)