Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Fixed `$ref` resolution for subschemas inside `allOf`, `anyOf`, `oneOf` and `items` arrays: an `$id` (or draft 04 `id`) there was not found, and a relative `$ref` there ignored the base URI of its parent `$id`
* Fixed `$id` and `$ref` inside `const`, `default`, `enum` and `examples` values being treated as schema keywords (a `$ref` there was rewritten to an absolute URI)
* Fixed quadratic backtracking in the `email` and `idn-email` format regexes on long invalid strings
* Fixed the `date`, `date-time` and `time` formats accepting non-ASCII digits (such as Bengali or fullwidth digits)
* Optimization: `$ref` inside an array or an object does not copy all local variables to make the name for each item
* Added support of dependentRequired and dependentSchemas from draft-2019

Expand Down
7 changes: 4 additions & 3 deletions fastjsonschema/draft04.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

# Calendar date: the day must exist in its month, and 29 February only in a leap year.
DATE_REGEX = (
r'\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|02-(?:0[1-9]|1\d|2[0-8]))'
r'|(?:\d\d(?:0[48]|[2468][048]|[13579][26])|(?:[02468][048]|[13579][26])00)-02-29'
r'[0-9]{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12][0-9]|3[01])'
r'|(?:0[469]|11)-(?:0[1-9]|[12][0-9]|30)|02-(?:0[1-9]|1[0-9]|2[0-8]))'
r'|(?:[0-9][0-9](?:0[48]|[2468][048]|[13579][26])|(?:[02468][048]|[13579][26])00)-02-29'
)


Expand All @@ -33,7 +34,7 @@ class CodeGeneratorDraft04(CodeGenerator):
# vs. 9 ms with a regex! Other modules are also ineffective or not available in standard
# library. Some regexps are not 100% precise but good enough, fast and without dependencies.
FORMAT_REGEXS = {
'date-time': r'^(?:' + DATE_REGEX + r')(t|T)(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:[+-](?:[01]\d|2[0-3]):[0-5]\d|[+-](?:[01]\d|2[0-3])[0-5]\d|z|Z)\Z',
'date-time': r'^(?:' + DATE_REGEX + r')(t|T)(?:[01][0-9]|2[0-3]):[0-5][0-9]:(?:[0-5][0-9]|60)(?:\.[0-9]+)?(?:[+-](?:[01][0-9]|2[0-3]):[0-5][0-9]|[+-](?:[01][0-9]|2[0-3])[0-5][0-9]|z|Z)\Z',
'email': r'^[^@.]+(?:\.[^@.]+)*@(?=[^@][^@.]*\.[^@])[^@]+\Z',
'hostname': r'^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])\Z',
'ipv4': r'^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\Z',
Expand Down
6 changes: 3 additions & 3 deletions fastjsonschema/draft07.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class CodeGeneratorDraft07(CodeGeneratorDraft06):
'relative-json-pointer': r'^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)\Z',
#'regex': r'',
'time': (
r'^(?P<hour>[01]?\d|2[0-3]):(?P<minute>[0-5]?\d)'
r'(?::(?P<second>[0-5]?\d|60)(?:\.(?P<microsecond>\d{1,6}))?'
r'([zZ]|[+-](?:[01]\d|2[0-3]):[0-5]\d)?)?\Z'
r'^(?P<hour>[01]?[0-9]|2[0-3]):(?P<minute>[0-5]?[0-9])'
r'(?::(?P<second>[0-5]?[0-9]|60)(?:\.(?P<microsecond>[0-9]{1,6}))?'
r'([zZ]|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])?)?\Z'
),
})

Expand Down
7 changes: 7 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
('2020-02-30T01:01:01Z', exc),
('2021-02-29T01:01:01Z', exc),
('2021-04-31T01:01:01Z', exc),
('1963-06-1\u09eaT00:00:00Z', exc),
('1963-06-11T0\u09ea:00:00Z', exc),
('2020-01-01T00:00:00.\u0661\u0662Z', exc),
('2020-02-29T01:01:01Z', '2020-02-29T01:01:01Z'),
('2021-04-30T01:01:01Z', '2021-04-30T01:01:01Z'),
])
Expand Down Expand Up @@ -124,6 +127,8 @@ def test_hostname(asserter, value, expected):
('12:00:61Z', exc),
('12:00:00+24:00', exc),
('12:00:00+00:60', exc),
('1\u09e8:00:00Z', exc),
('12:00:00.\u0661Z', exc),
])
def test_time(asserter, value, expected):
asserter({
Expand All @@ -147,6 +152,8 @@ def test_time(asserter, value, expected):
('2018-11-31', exc),
('1900-02-29', exc),
('2100-02-29', exc),
('1963-06-1\u09ea', exc),
('\uff12\uff10\uff11\uff18-02-05', exc),
('2020-02-29', '2020-02-29'),
('2000-02-29', '2000-02-29'),
('2400-02-29', '2400-02-29'),
Expand Down
Loading