WordPress.org

Make WordPress Core

Ticket #23881: 23881.3.diff

File 23881.3.diff, 1.6 KB (added by ericmann, 6 years ago)

Patch and matching unit test to verify Transient stability.

  • src/wp-includes/option.php

     
    451451                        $alloptions = wp_load_alloptions();
    452452                        if ( !isset( $alloptions[$transient_option] ) ) {
    453453                                $transient_timeout = '_transient_timeout_' . $transient;
    454                                 if ( get_option( $transient_timeout ) < time() ) {
     454                                $transient_timeout_value = get_option( $transient_timeout );
     455                                if ( false !== $transient_timeout_value && $transient_timeout_value < time() ) {
    455456                                        delete_option( $transient_option  );
    456457                                        delete_option( $transient_timeout );
    457458                                        $value = false;
  • tests/phpunit/tests/option/transient.php

     
    3333                $this->assertEquals( $value, get_transient( $key ) );
    3434                $this->assertTrue( delete_transient( $key ) );
    3535        }
     36
     37        /**
     38         * According to ticket 23881, requesting a transient beginning with "timeout_" and appending
     39         * a valid transient key would inadvertently delete the timeout for the original transient.
     40         * This test recreates that workflow (as to verify that the bug has been patched).
     41         *
     42         * @ticket 23881
     43         */
     44        function test_timeout_safe_delete() {
     45                $key = 'test';
     46                $value = '1234';
     47
     48                $this->assertTrue( set_transient( $key, $value, 60 * 60 ) );
     49                get_transient( "timeout_{$key}" );
     50
     51                // Verify our assertion
     52                $this->assertEquals( $value, get_transient( $key ) );
     53        }
    3654}