Make WordPress Core

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's profile 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)

patch.diff (494 bytes) - added by jonmcpartland 3 years ago.
53372.1.diff (1.7 KB) - added by jonmcpartland 3 years ago.
patch with tests

Download all attachments as: .zip

Change History (5)

@jonmcpartland
3 years ago

#1 @johnbillion
3 years ago

  • Keywords has-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version trunk deleted

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/

#2 @jonmcpartland
3 years ago

Hi @johnbillion

Thanks for the feedback. I am attaching a new diff with added unit tests.

Best
Jon

@jonmcpartland
3 years ago

patch with tests

#3 @johnbillion
3 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed
Note: See TracTickets for help on using tickets.