Opened 5 years ago
Last modified 18 months 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: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | REST API | Version: | |
| Severity: | minor | Keywords: | has-patch has-unit-tests close 2nd-opinion |
| Cc: | Focuses: | rest-api |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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/