Changeset 46965
- Timestamp:
- 12/16/2019 11:22:00 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r46862 r46965 2473 2473 // Prevent collisions with existing file names that contain dimension-like strings 2474 2474 // (whether they are subsizes or originals uploaded prior to #42437). 2475 $upload_dir = wp_get_upload_dir(); 2475 2476 2476 2477 // The (resized) image files would have name and extension, and will be in the uploads dir. 2477 if ( @is_dir( $dir ) && $name && $ext ) { 2478 // List of all files and directories contained in $dir (with the "dot" files removed). 2479 $files = array_diff( scandir( $dir ), array( '.', '..' ) ); 2478 if ( $name && $ext && @is_dir( $dir ) && false !== strpos( $dir, $upload_dir['basedir'] ) ) { 2479 // List of all files and directories contained in $dir. 2480 $files = @scandir( $dir ); 2481 2482 if ( ! empty( $files ) ) { 2483 // Remove "dot" dirs. 2484 $files = array_diff( $files, array( '.', '..' ) ); 2485 } 2480 2486 2481 2487 if ( ! empty( $files ) ) { -
trunk/tests/phpunit/tests/functions.php
r46835 r46965 202 202 $testdir = DIR_TESTDATA . '/images/'; 203 203 204 add_filter( 'upload_dir', array( $this, 'upload_dir_patch_basedir' ) ); 205 204 206 // Test collision with "dimension-like" original filename. 205 207 $this->assertEquals( 'one-blue-pixel-100x100-1.png', wp_unique_filename( $testdir, 'one-blue-pixel-100x100.png' ) ); … … 207 209 // Existing files: one-blue-pixel-100x100.png, one-blue-pixel-1-100x100.png. 208 210 $this->assertEquals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.png' ) ); 211 212 remove_filter( 'upload_dir', array( $this, 'upload_dir_patch_basedir' ) ); 213 } 214 215 // Callback to patch "basedir" when used in `wp_unique_filename()`. 216 function upload_dir_patch_basedir( $upload_dir ) { 217 $upload_dir['basedir'] = DIR_TESTDATA . '/images/'; 218 return $upload_dir; 209 219 } 210 220 … … 229 239 ), 230 240 ); 241 231 242 foreach ( $cases as $case ) { 232 243 $this->assertTrue( is_serialized( $case ), "Serialized data: $case" ); … … 238 249 's:4:test;', 239 250 ); 251 240 252 foreach ( $not_serialized as $case ) { 241 253 $this->assertFalse( is_serialized( $case ), "Test data: $case" );
Note: See TracChangeset
for help on using the changeset viewer.