Make WordPress Core

Changeset 59040


Ignore:
Timestamp:
09/17/2024 11:22:43 PM (2 years ago)
Author:
kadamwhite
Message:

REST API: Allow posts to be published with a publication date of midnight 1970-01-01.

Explicitly checks date parsing return values for false, so that 0 (the value returned for the UNIX epoch of 1970-01-01 00:00:00) is correctly treated as a valid timestamp.

It should be valid to create a post dated to any point in history.

Props emmanuel78, sabernhardt, siliconforks, drjosh07, antpb, TimothyBlynJacobs.
Fixes #60184.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r58933 r59040  
    13051305 * Parses an RFC3339 time into a Unix timestamp.
    13061306 *
     1307 * Explicitly check for `false` to detect failure, as zero is a valid return
     1308 * value on success.
     1309 *
    13071310 * @since 4.4.0
    13081311 *
     
    13701373        $date = rest_parse_date( $date );
    13711374
    1372         if ( empty( $date ) ) {
     1375        if ( false === $date ) {
    13731376                return null;
    13741377        }
     
    22602263
    22612264                        case 'date-time':
    2262                                 if ( ! rest_parse_date( $value ) ) {
     2265                                if ( false === rest_parse_date( $value ) ) {
    22632266                                        return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) );
    22642267                                }
  • trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php

    r55457 r59040  
    10191019                $this->assertWPError( $error );
    10201020                $this->assertSame( 'Invalid date.', $error->get_error_message() );
     1021        }
     1022
     1023        /**
     1024         * @ticket 60184
     1025         */
     1026        public function test_epoch() {
     1027                $schema = array(
     1028                        'type'   => 'string',
     1029                        'format' => 'date-time',
     1030                );
     1031                $this->assertTrue( rest_validate_value_from_schema( '1970-01-01T00:00:00Z', $schema ) );
    10211032        }
    10221033
Note: See TracChangeset for help on using the changeset viewer.