Make WordPress Core


Ignore:
Timestamp:
03/01/2019 08:57:26 PM (6 years ago)
Author:
jorbin
Message:

Replace usages of basename() with wp_basename() in order to support multibyte filenames

This is focused on the pieces of code that touch media files and the tests that support them. basename isn't multibyte compatible out of the box. See http://php.net/basename and https://bugs.php.net/bug.php?id=62119.

See #43170.
Props Viper007Bond.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/attachments.php

    r42343 r44785  
    2828        $contents = file_get_contents( $filename );
    2929
    30         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     30        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    3131        $this->assertTrue( empty( $upload['error'] ) );
    3232
     
    4040        // medium, medium_large, and full size will both point to the original
    4141        $downsize = image_downsize( $id, 'medium' );
    42         $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
     42        $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
    4343        $this->assertEquals( 50, $downsize[1] );
    4444        $this->assertEquals( 50, $downsize[2] );
    4545
    4646        $downsize = image_downsize( $id, 'medium_large' );
    47         $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
     47        $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
    4848        $this->assertEquals( 50, $downsize[1] );
    4949        $this->assertEquals( 50, $downsize[2] );
    5050
    5151        $downsize = image_downsize( $id, 'full' );
    52         $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
     52        $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
    5353        $this->assertEquals( 50, $downsize[1] );
    5454        $this->assertEquals( 50, $downsize[2] );
     
    6767        $contents = file_get_contents( $filename );
    6868
    69         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     69        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    7070        $this->assertTrue( empty( $upload['error'] ) );
    7171
     
    8787        // image_downsize() should return the correct images and sizes
    8888        $downsize = image_downsize( $id, 'thumbnail' );
    89         $this->assertEquals( 'a2-small-150x150.jpg', basename( $downsize[0] ) );
     89        $this->assertEquals( 'a2-small-150x150.jpg', wp_basename( $downsize[0] ) );
    9090        $this->assertEquals( 150, $downsize[1] );
    9191        $this->assertEquals( 150, $downsize[2] );
     
    9393        // medium, medium_large, and full will both point to the original
    9494        $downsize = image_downsize( $id, 'medium' );
    95         $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) );
     95        $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) );
    9696        $this->assertEquals( 400, $downsize[1] );
    9797        $this->assertEquals( 300, $downsize[2] );
    9898
    9999        $downsize = image_downsize( $id, 'medium_large' );
    100         $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) );
     100        $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) );
    101101        $this->assertEquals( 400, $downsize[1] );
    102102        $this->assertEquals( 300, $downsize[2] );
    103103
    104104        $downsize = image_downsize( $id, 'full' );
    105         $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) );
     105        $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) );
    106106        $this->assertEquals( 400, $downsize[1] );
    107107        $this->assertEquals( 300, $downsize[2] );
     
    123123        $contents = file_get_contents( $filename );
    124124
    125         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     125        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    126126        $this->assertTrue( empty( $upload['error'] ) );
    127127
     
    147147        // image_downsize() should return the correct images and sizes
    148148        $downsize = image_downsize( $id, 'thumbnail' );
    149         $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename( $downsize[0] ) );
     149        $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $downsize[0] ) );
    150150        $this->assertEquals( 150, $downsize[1] );
    151151        $this->assertEquals( 150, $downsize[2] );
    152152
    153153        $downsize = image_downsize( $id, 'medium' );
    154         $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', basename( $downsize[0] ) );
     154        $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', wp_basename( $downsize[0] ) );
    155155        $this->assertEquals( 400, $downsize[1] );
    156156        $this->assertEquals( 602, $downsize[2] );
    157157
    158158        $downsize = image_downsize( $id, 'medium_large' );
    159         $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', basename( $downsize[0] ) );
     159        $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', wp_basename( $downsize[0] ) );
    160160        $this->assertEquals( 600, $downsize[1] );
    161161        $this->assertEquals( 904, $downsize[2] );
    162162
    163163        $downsize = image_downsize( $id, 'full' );
    164         $this->assertEquals( '2007-06-17DSC_4173.jpg', basename( $downsize[0] ) );
     164        $this->assertEquals( '2007-06-17DSC_4173.jpg', wp_basename( $downsize[0] ) );
    165165        $this->assertEquals( 680, $downsize[1] );
    166166        $this->assertEquals( 1024, $downsize[2] );
     
    182182        $contents = file_get_contents( $filename );
    183183
    184         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     184        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    185185        $this->assertTrue( empty( $upload['error'] ) );
    186186
     
    225225        $contents = file_get_contents( $filename );
    226226
    227         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     227        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    228228        $this->assertTrue( empty( $upload['error'] ) );
    229229
     
    242242        $contents = file_get_contents( $filename );
    243243
    244         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     244        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    245245        $this->assertTrue( empty( $upload['error'] ) );
    246246
     
    268268        $contents = file_get_contents( $filename );
    269269
    270         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     270        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    271271        $this->assertTrue( empty( $upload['error'] ) );
    272272
     
    300300        $contents = file_get_contents( $filename );
    301301
    302         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     302        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    303303        $this->assertTrue( empty( $upload['error'] ) );
    304304
     
    325325        $contents = file_get_contents( $filename );
    326326
    327         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     327        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    328328        $this->assertTrue( empty( $upload['error'] ) );
    329329
     
    350350        $contents = file_get_contents( $filename );
    351351
    352         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     352        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    353353        $this->assertTrue( empty( $upload['error'] ) );
    354354
     
    378378        $contents = file_get_contents( $filename );
    379379
    380         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     380        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    381381        $this->assertTrue( empty( $upload['error'] ) );
    382382
     
    406406        $contents = file_get_contents( $filename );
    407407
    408         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     408        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    409409        $this->assertTrue( empty( $upload['error'] ) );
    410410
     
    433433        $contents = file_get_contents( $filename );
    434434
    435         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     435        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    436436        $this->assertTrue( empty( $upload['error'] ) );
    437437
     
    455455        $contents = file_get_contents( $filename );
    456456
    457         $upload        = wp_upload_bits( basename( $filename ), null, $contents );
     457        $upload        = wp_upload_bits( wp_basename( $filename ), null, $contents );
    458458        $attachment_id = $this->_make_attachment( $upload );
    459459
     
    473473        $contents = file_get_contents( $filename );
    474474
    475         $upload        = wp_upload_bits( basename( $filename ), null, $contents );
     475        $upload        = wp_upload_bits( wp_basename( $filename ), null, $contents );
    476476        $attachment_id = $this->_make_attachment( $upload );
    477477
     
    490490        $contents = file_get_contents( $filename );
    491491
    492         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     492        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    493493
    494494        $this->assertFalse( $upload['error'] );
     
    496496        add_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) );
    497497
    498         $upload = wp_upload_bits( basename( $filename ), null, $contents );
     498        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    499499
    500500        remove_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) );
Note: See TracChangeset for help on using the changeset viewer.