Make WordPress Core

Ticket #53372: 53372.1.diff

File 53372.1.diff, 1.7 KB (added by jonmcpartland, 4 years ago)

patch with tests

  • src/wp-includes/rest-api.php

    diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
    index 9a615419b9..cc326eb0da 100644
    a b function rest_validate_value_from_schema( $value, $args, $param = '' ) { 
    21512151                                break;
    21522152
    21532153                        case 'date-time':
    2154                                 if ( ! rest_parse_date( $value ) ) {
     2154                                if ( false === rest_parse_date( $value ) ) {
    21552155                                        return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) );
    21562156                                }
    21572157                                break;
  • tests/phpunit/tests/rest-api/rest-schema-validation.php

    diff --git a/tests/phpunit/tests/rest-api/rest-schema-validation.php b/tests/phpunit/tests/rest-api/rest-schema-validation.php
    index 2fab13fe0a..b3c87a902a 100644
    a b class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { 
    103103                        'type'   => 'string',
    104104                        'format' => 'date-time',
    105105                );
     106                $this->assertTrue( rest_validate_value_from_schema( '1970-01-01T00:00:00', $schema ) );
     107                $this->assertTrue( rest_validate_value_from_schema( '1970-01-01T00:00:00Z', $schema ) );
    106108                $this->assertTrue( rest_validate_value_from_schema( '2016-06-30T05:43:21', $schema ) );
    107109                $this->assertTrue( rest_validate_value_from_schema( '2016-06-30T05:43:21Z', $schema ) );
    108110                $this->assertTrue( rest_validate_value_from_schema( '2016-06-30T05:43:21+00:00', $schema ) );
     111                $this->assertWPError( rest_validate_value_from_schema( '19700101T000000Z', $schema ) );
    109112                $this->assertWPError( rest_validate_value_from_schema( '20161027T163355Z', $schema ) );
    110113                $this->assertWPError( rest_validate_value_from_schema( '2016', $schema ) );
    111114                $this->assertWPError( rest_validate_value_from_schema( '2016-06-30', $schema ) );