Make WordPress Core

Changeset 52482 for branches/4.1


Ignore:
Timestamp:
01/06/2022 06:23:29 PM (2 years ago)
Author:
desrosj
Message:

Grouped backports to the 4.1 branch.

  • Query: Improve sanitization within WP_Tax_Query.
  • Query: Improve sanitization within WP_Meta_Query.
  • Upgrade/Install: Avoid using unserialize() unnecessarily.
  • Formatting: Correctly encode ASCII characters in post slugs.

Merges [52454-52457] to the 4.1 branch.
Props vortfu, dd32, ehtis, zieladam, whyisjake, xknown, peterwilsoncc, desrosj, iandunn.

Location:
branches/4.1
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

  • branches/4.1/src/wp-admin/includes/upgrade.php

    r32431 r52482  
    10781078        while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
    10791079            foreach( $rows as $row ) {
    1080                 $value = $row->option_value;
    1081                 if ( !@unserialize( $value ) )
     1080                $value = maybe_unserialize( $row->option_value );
     1081                if ( $value === $row->option_value )
    10821082                    $value = stripslashes( $value );
    10831083                if ( $value !== $row->option_value ) {
  • branches/4.1/src/wp-includes/formatting.php

    r47658 r52482  
    864864 *
    865865 * @since 1.5.0
     866 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
    866867 *
    867868 * @param string $utf8_string
    868869 * @param int $length Max length of the string
     870 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    869871 * @return string String with Unicode encoded for URI.
    870872 */
    871 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     873function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    872874    $unicode = '';
    873875    $values = array();
     
    884886
    885887        if ( $value < 128 ) {
    886             if ( $length && ( $unicode_length >= $length ) )
     888            $char                = chr( $value );
     889            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     890            $encoded_char_length = strlen( $encoded_char );
     891            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    887892                break;
    888             $unicode .= chr($value);
    889             $unicode_length++;
     893            }
     894            $unicode        .= $encoded_char;
     895            $unicode_length += $encoded_char_length;
    890896        } else {
    891897            if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
  • branches/4.1/src/wp-includes/meta.php

    r49405 r52482  
    15021502            $sibling_compare = strtoupper( $sibling['compare'] );
    15031503            if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) {
    1504                 $alias = $sibling['alias'];
     1504                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    15051505                break;
    15061506            }
  • branches/4.1/src/wp-includes/post.php

    r43401 r52482  
    37843784            $slug = substr( $slug, 0, $length );
    37853785        else
    3786             $slug = utf8_uri_encode( $decoded_slug, $length );
     3786            $slug = utf8_uri_encode( $decoded_slug, $length, true );
    37873787    }
    37883788
  • branches/4.1/src/wp-includes/taxonomy.php

    r37138 r52482  
    11471147            // The sibling must both have compatible operator to share its alias.
    11481148            if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
    1149                 $alias = $sibling['alias'];
     1149                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    11501150                break;
    11511151            }
     
    11771177        }
    11781178
    1179         $query['terms'] = array_unique( (array) $query['terms'] );
     1179        if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
     1180            $query['terms'] = array_unique( (array) $query['terms'] );
     1181        } else {
     1182            $query['terms'] = wp_parse_id_list( $query['terms'] );
     1183        }
    11801184
    11811185        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
Note: See TracChangeset for help on using the changeset viewer.