Skip to content

fix: reject time values with out of range fields - #75

Open
EmiRZx wants to merge 1 commit into
cloudevents:mainfrom
EmiRZx:fix-time-overflow
Open

EmiRZx wants to merge 1 commit into
cloudevents:mainfrom
EmiRZx:fix-time-overflow

Conversation

@EmiRZx

@EmiRZx EmiRZx commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

fixes #74. decode() now checks the warnings from DateTimeImmutable::getLastErrors() and throws the same ValueError as for other invalid values. the deserializers still turn it into InvalidAttributeException. valid values decode as before and forms like +0200 are unchanged. a leap second like 23:59:60 is rejected too. it used to roll over to the next minute. Go, Python and JavaScript reject it as well.

the six new cases fail on main and pass here. tests pass on PHP 8.1, 8.4 and 8.5. a check of 37 values gives the same results on 7.4, 8.0, 8.4 and 8.5 and only the ten values with out of range fields change. phpcs and psalm are clean. it merges cleanly with #68 and #72.

DateTimeImmutable::createFromFormat() moves fields that are out of
range into the next unit and only reports a warning. So a time of
2018-02-30T10:00:00Z was read as 2018-03-02T10:00:00Z and 24:30
became 00:30 on the next day. Such values are now rejected like any
other invalid time. This includes a leap second like 23:59:60, which
used to roll over to the next minute.

Signed-off-by: emir <52245396+EmiRZx@users.noreply.github.com>
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.

Invalid time values are moved to another time instead of rejected

1 participant