Make WordPress Core

Changeset 35276


Ignore:
Timestamp:
10/20/2015 04:04:26 AM (8 years ago)
Author:
wonderboymusic
Message:

Formatting: when making unique filenames in wp_unique_filename() by adding an incrementing number, prefix it with a dash to disambiguate from files that end in numbers.

Updates unit tests.

Props mikejolley, tyxla.
Fixes #21453.

Location:
trunk
Files:
2 edited

Legend:

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

    r35170 r35276  
    19191919            while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
    19201920                $new_number = $number + 1;
    1921                 $filename = str_replace( "$number$ext", "$new_number$ext", $filename );
    1922                 $filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
     1921                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
     1922                $filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
    19231923                $number = $new_number;
    19241924            }
     
    19271927
    19281928        while ( file_exists( $dir . "/$filename" ) ) {
    1929             if ( '' == "$number$ext" )
    1930                 $filename = $filename . ++$number . $ext;
    1931             else
    1932                 $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
     1929            if ( '' == "$number$ext" ) {
     1930                $filename = "$filename-" . ++$number;
     1931            } else {
     1932                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename );
     1933            }
    19331934        }
    19341935    }
  • trunk/tests/phpunit/tests/functions.php

    r35242 r35276  
    147147        // check number is appended for file already exists
    148148        $this->assertFileExists( $testdir . 'test-image.png', 'Test image does not exist' );
    149         $this->assertEquals( 'test-image1.png', wp_unique_filename( $testdir, 'test-image.png' ), 'Number not appended correctly' );
    150         $this->assertFileNotExists( $testdir . 'test-image1.png' );
     149        $this->assertEquals( 'test-image-1.png', wp_unique_filename( $testdir, 'test-image.png' ), 'Number not appended correctly' );
     150        $this->assertFileNotExists( $testdir . 'test-image-1.png' );
    151151
    152152        // check special chars
Note: See TracChangeset for help on using the changeset viewer.