Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API: fix handling of the epoch #7277

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/tests/rest-api/rest-schema-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
Loading