WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/01/2019 08:57:26 PM (6 months 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/src/wp-includes/post.php

    r44687 r44785  
    54755475        // Don't delete the thumb if another attachment uses it.
    54765476        if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
    5477             $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file );
     5477            $thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file );
    54785478            if ( ! empty( $thumbfile ) ) {
    54795479                $thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
     
    54915491        $intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
    54925492        foreach ( $meta['sizes'] as $size => $sizeinfo ) {
    5493             $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
     5493            $intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file );
    54945494            if ( ! empty( $intermediate_file ) ) {
    54955495                $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
     
    56175617            } elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) {
    56185618                // Get the directory name relative to the basedir (back compat for pre-2.7 uploads)
    5619                 $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file );
     5619                $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . wp_basename( $file );
    56205620            } else {
    56215621                // It's a newly-uploaded file, therefore $file is relative to the basedir.
     
    57055705    $file = get_attached_file( $post->ID );
    57065706
    5707     if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) {
     5707    if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) {
    57085708        /**
    57095709         * Filters the attachment thumbnail file path.
     
    57455745    }
    57465746
    5747     $url = str_replace( basename( $url ), basename( $thumb ), $url );
     5747    $url = str_replace( wp_basename( $url ), wp_basename( $thumb ), $url );
    57485748
    57495749    /**
     
    58975897                if ( $dh = opendir( $dir ) ) {
    58985898                    while ( false !== $file = readdir( $dh ) ) {
    5899                         $file = basename( $file );
     5899                        $file = wp_basename( $file );
    59005900                        if ( substr( $file, 0, 1 ) == '.' ) {
    59015901                            continue;
     
    59165916
    59175917        $types = array();
    5918         // Icon basename - extension = MIME wildcard.
     5918        // Icon wp_basename - extension = MIME wildcard.
    59195919        foreach ( $icon_files as $file => $uri ) {
    5920             $types[ preg_replace( '/^([^.]*).*$/', '$1', basename( $file ) ) ] =& $icon_files[ $file ];
     5920            $types[ preg_replace( '/^([^.]*).*$/', '$1', wp_basename( $file ) ) ] =& $icon_files[ $file ];
    59215921        }
    59225922
Note: See TracChangeset for help on using the changeset viewer.