WordPress.org

Make WordPress Core

Ticket #33999: 33999.diff

File 33999.diff, 1.1 KB (added by boonebgorges, 4 years ago)
  • src/wp-admin/includes/file.php

    diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
    index a11bc95..b2c8080 100644
    function wp_tempnam( $filename = '', $dir = '' ) { 
    148148                $dir = get_temp_dir();
    149149        }
    150150
    151         if ( empty( $filename ) || '.' == $filename || '/' == $filename ) {
     151        if ( empty( $filename ) || '.' == $filename || DIRECTORY_SEPARATOR == $filename ) {
    152152                $filename = time();
    153153        }
    154154
  • tests/phpunit/tests/file.php

    diff --git tests/phpunit/tests/file.php tests/phpunit/tests/file.php
    index 8ee3e8d..5472ebb 100644
    class Tests_File extends WP_UnitTestCase { 
    175175                );
    176176        }
    177177
     178        /**
     179         * @ticket 33999
     180         */
     181        public function test_wp_tempnam_should_use_timestamp_for_filename_when_filename_is_directory_separator() {
     182                $now = time();
     183                $file = wp_tempnam( DIRECTORY_SEPARATOR );
     184
     185                $filename = basename( $file );
     186
     187                // Only check the first few characters, to account for elapsed second(s).
     188                $this->assertSame( substr( $now, 0, 5 ), substr( $filename, 0, 5 ) );
     189        }
     190
    178191}