Make WordPress Core

Ticket #22363: 22363.12.patch

File 22363.12.patch, 4.2 KB (added by gitlost, 9 years ago)

A minimal patch.

  • src/wp-includes/default-filters.php

     
    197197add_filter( 'teeny_mce_before_init',    '_mce_set_direction'                  );
    198198add_filter( 'pre_kses',                 'wp_pre_kses_less_than'               );
    199199add_filter( 'sanitize_title',           'sanitize_title_with_dashes',   10, 3 );
     200add_filter( 'sanitize_file_name',       'remove_accents'                      );
    200201add_action( 'check_comment_flood',      'check_comment_flood_db',       10, 3 );
    201202add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',    10, 3 );
    202203add_filter( 'pre_comment_content',      'wp_rel_nofollow',              15    );
  • src/wp-includes/formatting.php

     
    17641764         * @param string $filename_raw  Filename as it was passed into sanitize_file_name().
    17651765         */
    17661766        $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
    1767         $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
    17681767        $filename = str_replace( $special_chars, '', $filename );
    1769         $filename = str_replace( array( '%20', '+' ), '-', $filename );
     1768        if ( ! seems_utf8( $filename ) ) {
     1769                // Reduce to ASCII.
     1770                $filename = preg_replace( '/[\x80-\xff]/', '-', $filename );
     1771        }
     1772        $filename = str_replace( array( '%20', '+', "\xc2\xa0" ), '-', $filename );
    17701773        $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
    17711774        $filename = trim( $filename, '.-_' );
    17721775
  • tests/phpunit/tests/formatting/SanitizeFileName.php

     
    4747
    4848        function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
    4949                $this->assertEquals("a-t", sanitize_file_name("a          t"));
    50                 $this->assertEquals("a-t", sanitize_file_name("a    \n\n\nt"));
     50                $this->assertEquals("a-t", sanitize_file_name("a    \t\r\n\n\nt"));
    5151        }
    5252
    5353        /**
     
    6767                // Test a filenames that becomes extensionless.
    6868                $this->assertEquals( 'no-extension', sanitize_file_name( '_.no-extension' ) );
    6969        }
     70
     71        /**
     72         * @ticket 22363
     73         */
     74        function test_replaces_utf8_whitespace() {
     75                $this->assertEquals("non-breaking", sanitize_file_name("non\xc2\xa0breaking"));
     76        }
     77
     78        /**
     79         * @ticket 22363
     80         */
     81        function test_replaces_accents() {
     82                $in  = 'àáâãäåæçèéêëìíîïñòóôõöøùúûüýÿ';
     83                $out = 'aaaaaaaeceeeeiiiinoooooouuuuyy';
     84                $this->assertEquals( $out, sanitize_file_name( $in ) );
     85        }
     86
     87        /**
     88         * @ticket 22363
     89         * @ticket 24661
     90         */
     91        /* Requires #24661 fix
     92        function test_replaces_combining_accents() {
     93                $in  = 'àáâãäåçèéêëìíîïñòóôõöùúûüýÿ';
     94                $out = 'aaaaaaceeeeiiiinooooouuuuyy';
     95                $this->assertEquals( $out, sanitize_file_name( $in ) );
     96        }
     97        */
     98
     99        /**
     100         * @ticket 22363
     101         */
     102        function test_strips_non_alpha_html_entities() {
     103                $this->assertEquals("start-copy-amp-euro-ndash-nbsp-end", sanitize_file_name( "start © & € –   end" ) );
     104                $this->assertEquals("start-invalid-end", sanitize_file_name( "start &invalid; end" ) );
     105        }
     106
     107        /**
     108         * @ticket 22363
     109         */
     110        function test_converts_alpha_html_entities() {
     111                $this->assertEquals("start-agrave-ecirc-ntilde-oslash-aelig-end", sanitize_file_name("start à ê ñ ø æ end" ) );
     112        }
     113
     114        /**
     115         * @ticket 22363
     116         */
     117        function test_removes_some_non_alphanum_characters() {
     118                $test_input = "start ¿”©“? «±€—°» middle “√¼ = ♫” & „☺ + ☻ = ♥‟ end";
     119                $this->assertEquals("start-¿”©“-«±E—°»-middle-“√¼-♫”-„☺-☻-♥‟-end", sanitize_file_name( $test_input ) );
     120        }
     121
     122        /**
     123         * @ticket 22363
     124         */
     125        function test_removes_nonascii_on_invalid_utf8() {
     126                $this->assertEquals( 'Invalid-utf8', sanitize_file_name( "Invalid \xff utf8" ) );
     127        }
    70128}