Make WordPress Core

Changeset 47658


Ignore:
Timestamp:
04/29/2020 04:52:21 PM (4 years ago)
Author:
whyisjake
Message:

User: Invalidate user_activation_key on password update.
Query: Ensure that only a single post can be returned on date/time based queries.
Cache API: Ensure proper escaping around the stats method in the cache API.
Formatting: Expand sanitize_file_name to have better support for utf8 characters.

Brings the changes in [47634], [47635], [47637], and [47638] to the 4.1 branch.

Props: batmoo, ehti, nickdaugherty, peterwilsoncc, sergeybiryukov, sstoqnov, westi, whyisjake, whyisjake, xknown.

Location:
branches/4.1
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/src/wp-includes/cache.php

    r30681 r47658  
    640640        echo '<ul>';
    641641        foreach ($this->cache as $group => $cache) {
    642             echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>';
     642            echo '<li><strong>Group:</strong> ' . esc_html( $group ) . ' - ( ' . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
    643643        }
    644644        echo '</ul>';
  • branches/4.1/src/wp-includes/formatting.php

    r37818 r47658  
    11671167    $filename_raw = $filename;
    11681168    $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
     1169
     1170    // Check for support for utf8 in the installed PCRE library once and store the result in a static.
     1171    static $utf8_pcre = null;
     1172    if ( ! isset( $utf8_pcre ) ) {
     1173        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
     1174        $utf8_pcre = @preg_match( '/^./u', 'a' );
     1175    }
     1176
     1177    if ( ! seems_utf8( $filename ) ) {
     1178        $_ext     = pathinfo( $filename, PATHINFO_EXTENSION );
     1179        $_name    = pathinfo( $filename, PATHINFO_FILENAME );
     1180        $filename = sanitize_title_with_dashes( $_name ) . '.' . $_ext;
     1181    }
     1182
     1183    if ( $utf8_pcre ) {
     1184        $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
     1185    }
     1186
    11691187    /**
    11701188     * Filter the list of characters to remove from a filename.
     
    11761194     */
    11771195    $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
    1178     $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
    11791196    $filename = str_replace( $special_chars, '', $filename );
    11801197    $filename = str_replace( array( '%20', '+' ), '-', $filename );
  • branches/4.1/src/wp-includes/query.php

    r46501 r47658  
    15911591        } elseif ( $qv['p'] ) {
    15921592            $this->is_single = true;
    1593         } elseif ( ('' !== $qv['hour']) && ('' !== $qv['minute']) &&('' !== $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day']) ) {
    1594             // If year, month, day, hour, minute, and second are set, a single
    1595             // post is being queried.
    1596             $this->is_single = true;
    15971593        } elseif ( '' != $qv['pagename'] || !empty($qv['page_id']) ) {
    15981594            $this->is_page = true;
  • branches/4.1/src/wp-includes/user.php

    r30940 r47658  
    18861886
    18871887    if ( $update ) {
    1888         if ( $user_email !== $old_user_data->user_email ) {
     1888        if ( $user_email !== $old_user_data->user_email || $user_pass !== $old_user_data->user_pass ) {
    18891889            $data['user_activation_key'] = '';
    18901890        }
  • branches/4.1/tests/phpunit/tests/formatting/SanitizeFileName.php

    r37818 r47658  
    6161        $this->assertEquals( 'no-extension', sanitize_file_name( '_.no-extension' ) );
    6262    }
     63
     64    /**
     65     * @dataProvider data_wp_filenames
     66     */
     67    function test_replaces_invalid_utf8_characters( $input, $expected ) {
     68        $this->assertEquals( $expected, sanitize_file_name( $input ) );
     69    }
     70
     71    function data_wp_filenames() {
     72        return array(
     73            array( urldecode( '%B1myfile.png' ), 'myfile.png' ),
     74            array( urldecode( '%B1myfile' ), 'myfile' ),
     75            array( 'demo bar.png', 'demo-bar.png' ),
     76            array( 'demo' . json_decode( '"\u00a0"' ) . 'bar.png', 'demo-bar.png' ),
     77        );
     78    }
    6379}
  • branches/4.1/tests/phpunit/tests/user.php

    r30513 r47658  
    634634    }
    635635
    636     function test_changing_email_invalidates_password_reset_key() {
     636    public function test_changing_email_invalidates_password_reset_key() {
    637637        global $wpdb;
    638638
     
    665665        $this->assertEmpty( $user->user_activation_key );
    666666    }
     667
     668    public function test_changing_password_invalidates_password_reset_key() {
     669        global $wpdb;
     670
     671        $user = $this->factory->user->create_and_get();
     672        $wpdb->update( $wpdb->users, array( 'user_activation_key' => 'key' ), array( 'ID' => $user->ID ) );
     673        clean_user_cache( $user );
     674
     675        $user = get_userdata( $user->ID );
     676        $this->assertEquals( 'key', $user->user_activation_key );
     677
     678        $userdata = array(
     679            'ID'        => $user->ID,
     680            'user_pass' => 'password',
     681        );
     682        wp_update_user( $userdata );
     683
     684        $user = get_userdata( $user->ID );
     685        $this->assertEmpty( $user->user_activation_key );
     686    }
     687
    667688}
Note: See TracChangeset for help on using the changeset viewer.