Opened 3 years ago
Last modified 3 years ago
#53372 new defect (bug)
Loose type check against dates in rest_validate_value_from_schema causes invalidation for valid timestamp
Reported by: | jonmcpartland | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | minor | Version: | |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | rest-api | Cc: |
Description
When validating dates, rest_validate_value_from_schema
assumes a falsy return value from rest_parse_date
always means that the date is invalid (see [wp-includes/rest-api.php@L2138](https://github.com/WordPress/wordpress-develop/blob/5.7/src/wp-includes/rest-api.php#L2138). This is correct in all but one case (to my knowledge).
A perfectly valid date would be 1970-01-01 00:00:00
. However, since that date would produce a return value from rest_parse_date
of 0
, rest_validate_value_from_schema
assumes it is invalid.
Since rest_parse_date
returns the return value of strtotime
, checking that the return value is false
— rather than falsy — would be sufficient to resolve.
Attachments (2)
Change History (5)
Note: See
TracTickets for help on using
tickets.
Welcome @jonmcpartland , good catch! This seems correct to me but it would benefit from some tests.
https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/