Make WordPress Core

Ticket #50136: 50136.patch

File 50136.patch, 2.6 KB (added by ayeshrajans, 4 years ago)
  • src/wp-includes/ms-functions.php

    diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php
    index dae8d4f742..4303983af8 100644
    a b function get_most_recent_post_of_user( $user_id ) { 
    18451845 * @return array
    18461846 */
    18471847function check_upload_mimes( $mimes ) {
    1848         $site_exts  = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
    1849         $site_mimes = array();
    1850         foreach ( $site_exts as $ext ) {
    1851                 foreach ( $mimes as $ext_pattern => $mime ) {
    1852                         if ( '' != $ext && false !== strpos( $ext_pattern, $ext ) ) {
    1853                                 $site_mimes[ $ext_pattern ] = $mime;
    1854                         }
    1855                 }
    1856         }
    1857         return $site_mimes;
     1848    return filter_upload_mimes( $mimes, get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
     1849}
     1850
     1851/**
     1852 * A helper functions to filter a given list of mime types
     1853 * against a list of space-separated file extensions.
     1854 *
     1855 * File extensions are matched as a full-word. Return value
     1856 * will contain the passed $mimes array with only allowed
     1857 * values from $file_types.
     1858 *
     1859 * @param array $mimes
     1860 * @param $file_types
     1861 * @return array
     1862 */
     1863function filter_upload_mimes( array $mimes, $file_types ) {
     1864    $site_exts  = explode( ' ', $file_types );
     1865    $site_mimes = array();
     1866    foreach ( $site_exts as $ext ) {
     1867        foreach ( $mimes as $ext_pattern => $mime ) {
     1868            if ( '' != $ext && preg_match('/\b'. preg_quote($ext, '/') .'\b/', $ext_pattern)) {
     1869                $site_mimes[ $ext_pattern ] = $mime;
     1870            }
     1871        }
     1872    }
     1873    return $site_mimes;
    18581874}
    18591875
    18601876/**
  • new file tests/phpunit/tests/multisite/fileUploads.php

    diff --git a/tests/phpunit/tests/multisite/fileUploads.php b/tests/phpunit/tests/multisite/fileUploads.php
    new file mode 100644
    index 0000000000..40f86ea07c
    - +  
     1<?php
     2
     3if ( is_multisite() ) :
     4
     5    /**
     6     * @ticket 50136
     7     * @group ms-site
     8     * @group multisite
     9     */
     10    class Tests_Multisite_Upload_Mimes extends WP_UnitTestCase {
     11
     12        public function test_file_extensions_are_allowed_on_full_match() {
     13            $mimes = [
     14                'srt|txt|png' => 'foo',
     15                'tx' => 'bar',
     16                't' => 'baz',
     17            ];
     18
     19            $allowed_mimes = filter_upload_mimes($mimes, 'txt xf rt t');
     20            $this->assertTrue(isset($allowed_mimes['srt|txt|png']));
     21            $this->assertTrue(isset($allowed_mimes['t']));
     22            $this->assertFalse(isset($allowed_mimes['tx']));
     23            $this->assertFalse(isset($allowed_mimes['rt']));
     24            $this->assertFalse(isset($allowed_mimes['xf']));
     25        }
     26    }
     27
     28endif;
     29