Make WordPress Core

Changeset 52471 for branches/5.2


Ignore:
Timestamp:
01/06/2022 06:11:57 PM (3 years ago)
Author:
desrosj
Message:

Grouped backports to the 5.2 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 5.2 branch.
Props vortfu, dd32, ehtis, zieladam, whyisjake, xknown, peterwilsoncc, desrosj, iandunn.

Location:
branches/5.2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

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

    r45030 r52471  
    15921592        while ( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
    15931593            foreach ( $rows as $row ) {
    1594                 $value = $row->option_value;
    1595                 if ( ! @unserialize( $value ) ) {
     1594                $value = maybe_unserialize( $row->option_value );
     1595                if ( $value === $row->option_value ) {
    15961596                    $value = stripslashes( $value );
    15971597                }
  • branches/5.2/src/wp-includes/class-wp-meta-query.php

    r44518 r52471  
    732732            $sibling_compare = strtoupper( $sibling['compare'] );
    733733            if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) {
    734                 $alias = $sibling['alias'];
     734                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    735735                break;
    736736            }
  • branches/5.2/src/wp-includes/class-wp-tax-query.php

    r43571 r52471  
    527527            // The sibling must both have compatible operator to share its alias.
    528528            if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
    529                 $alias = $sibling['alias'];
     529                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    530530                break;
    531531            }
     
    556556        }
    557557
    558         $query['terms'] = array_unique( (array) $query['terms'] );
     558        if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
     559            $query['terms'] = array_unique( (array) $query['terms'] );
     560        } else {
     561            $query['terms'] = wp_parse_id_list( $query['terms'] );
     562        }
    559563
    560564        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
  • branches/5.2/src/wp-includes/formatting.php

    r47645 r52471  
    11511151 *
    11521152 * @since 1.5.0
    1153  *
    1154  * @param string $utf8_string
    1155  * @param int    $length Max  length of the string
     1153 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
     1154 *
     1155 * @param string $utf8_string             String to encode.
     1156 * @param int    $length                  Max length of the string
     1157 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    11561158 * @return string String with Unicode encoded for URI.
    11571159 */
    1158 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     1160function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    11591161    $unicode        = '';
    11601162    $values         = array();
     
    11711173
    11721174        if ( $value < 128 ) {
    1173             if ( $length && ( $unicode_length >= $length ) ) {
     1175            $char                = chr( $value );
     1176            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     1177            $encoded_char_length = strlen( $encoded_char );
     1178            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    11741179                break;
    11751180            }
    1176             $unicode .= chr( $value );
    1177             $unicode_length++;
     1181            $unicode        .= $encoded_char;
     1182            $unicode_length += $encoded_char_length;
    11781183        } else {
    11791184            if ( count( $values ) == 0 ) {
  • branches/5.2/src/wp-includes/post.php

    r47645 r52471  
    42984298            $slug = substr( $slug, 0, $length );
    42994299        } else {
    4300             $slug = utf8_uri_encode( $decoded_slug, $length );
     4300            $slug = utf8_uri_encode( $decoded_slug, $length, true );
    43014301        }
    43024302    }
Note: See TracChangeset for help on using the changeset viewer.