diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 9b023e97ece1b..75f31adf4c713 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -1304,6 +1304,10 @@ function rest_get_avatar_sizes() { /** * Parses an RFC3339 time into a Unix timestamp. * + * Warning: This function returns Boolean false on failure, but it may also + * return zero (which evaluates to false) on success. Use the === operator when + * checking for failure. + * * @since 4.4.0 * * @param string $date RFC3339 timestamp. @@ -1369,7 +1373,7 @@ function rest_get_date_with_gmt( $date, $is_utc = false ) { $date = rest_parse_date( $date ); - if ( empty( $date ) ) { + if ( false === $date ) { return null; } @@ -2259,7 +2263,7 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) { break; case 'date-time': - if ( ! rest_parse_date( $value ) ) { + if ( false === rest_parse_date( $value ) ) { return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) ); } break; diff --git a/tests/phpunit/tests/rest-api/rest-schema-validation.php b/tests/phpunit/tests/rest-api/rest-schema-validation.php index 67f01356d93da..ce8875c3e9339 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-validation.php +++ b/tests/phpunit/tests/rest-api/rest-schema-validation.php @@ -1020,6 +1020,17 @@ public function test_nullable_date() { $this->assertSame( 'Invalid date.', $error->get_error_message() ); } + /** + * @ticket 60184 + */ + public function test_epoch() { + $schema = array( + 'type' => 'string', + 'format' => 'date-time', + ); + $this->assertTrue( rest_validate_value_from_schema( '1970-01-01T00:00:00Z', $schema ) ); + } + public function test_object_or_string() { $schema = array( 'type' => array( 'object', 'string' ),