Skip to content

Validate the hour, minute, second and offset ranges of the time format - #227

Merged
horejsek merged 1 commit into
horejsek:masterfrom
pcbeingused333:fix/time-field-ranges
Oct 21, 2026
Merged

horejsek merged 1 commit into
horejsek:masterfrom
pcbeingused333:fix/time-field-ranges

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

The time format regex (draft 7 and later) checks the hour, minute and second with \d{1,2} and the offset with \d\d:\d\d, so it accepts values that cannot be RFC 3339 times:

>>> validate = fastjsonschema.compile({'$schema': 'http://json-schema.org/draft-07/schema', 'format': 'time'})
>>> validate('29:99:99')          # accepted
>>> validate('12:00:00+24:00')    # accepted
>>> validate('12:00:61Z')         # accepted

The regex now uses 0-23 for the hour, 0-59 for the minute, 0-60 for the seconds (RFC 3339 leap second) and (?:[01]\d|2[0-3]):[0-5]\d for the offset. The shape is unchanged: the one-digit forms and the optional seconds/offset that the regex already accepted stay accepted, as this is the same approach as the date-time fix in #225.

Tests: a new test_time in tests/test_format.py with 14 rows (five valid values including the leap second, two malformed values, seven out-of-range values). The seven out-of-range rows fail on master and all pass with this change; the rest of the suite passes (631 passed, 4 skipped, with tests/benchmarks left out). CHANGELOG.txt has an entry under UNRELEASED.

This change was made with Claude Code.

🤖 Generated with Claude Code

The time regex used \d{1,2} for the hour, minute and second and \d\d:\d\d
for the offset, so values such as 29:99:99 or 12:00:00+24:00 were
accepted. Use 0-23 for the hour, 0-59 for the minute, 0-60 for the
second (RFC 3339 leap second) and 00-23:00-59 for the offset. The
optional parts and the one-digit forms the regex already accepted are
unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@horejsek
horejsek merged commit 738da70 into horejsek:master Oct 21, 2026
16 of 17 checks passed
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.

2 participants