Make WordPress Core

Changeset 52479


Ignore:
Timestamp:
01/06/2022 06:18:04 PM (5 months ago)
Author:
desrosj
Message:

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

Location:
branches/4.4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

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

    r37936 r52479  
    12171217        while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
    12181218            foreach ( $rows as $row ) {
    1219                 $value = $row->option_value;
    1220                 if ( !@unserialize( $value ) )
     1219                $value = maybe_unserialize( $row->option_value );
     1220                if ( $value === $row->option_value )
    12211221                    $value = stripslashes( $value );
    12221222                if ( $value !== $row->option_value ) {
  • branches/4.4/src/wp-includes/class-wp-meta-query.php

    r35170 r52479  
    714714            $sibling_compare = strtoupper( $sibling['compare'] );
    715715            if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) {
    716                 $alias = $sibling['alias'];
     716                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    717717                break;
    718718            }
  • branches/4.4/src/wp-includes/class-wp-tax-query.php

    r34402 r52479  
    544544            // The sibling must both have compatible operator to share its alias.
    545545            if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
    546                 $alias = $sibling['alias'];
     546                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    547547                break;
    548548            }
     
    574574        }
    575575
    576         $query['terms'] = array_unique( (array) $query['terms'] );
     576        if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
     577            $query['terms'] = array_unique( (array) $query['terms'] );
     578        } else {
     579            $query['terms'] = wp_parse_id_list( $query['terms'] );
     580        }
    577581
    578582        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
  • branches/4.4/src/wp-includes/formatting.php

    r49402 r52479  
    10651065 *
    10661066 * @since 1.5.0
    1067  *
    1068  * @param string $utf8_string
    1069  * @param int    $length Max  length of the string
     1067 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
     1068 *
     1069 * @param string $utf8_string             String to encode.
     1070 * @param int    $length                  Max length of the string
     1071 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    10701072 * @return string String with Unicode encoded for URI.
    10711073 */
    1072 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     1074function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    10731075    $unicode        = '';
    10741076    $values         = array();
     
    10851087
    10861088        if ( $value < 128 ) {
    1087             if ( $length && ( $unicode_length >= $length ) ) {
     1089            $char                = chr( $value );
     1090            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     1091            $encoded_char_length = strlen( $encoded_char );
     1092            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    10881093                break;
    10891094            }
    1090             $unicode .= chr( $value );
    1091             $unicode_length++;
     1095            $unicode        .= $encoded_char;
     1096            $unicode_length += $encoded_char_length;
    10921097        } else {
    10931098            if ( count( $values ) == 0 ) {
  • branches/4.4/src/wp-includes/post.php

    r43398 r52479  
    36893689            $slug = substr( $slug, 0, $length );
    36903690        else
    3691             $slug = utf8_uri_encode( $decoded_slug, $length );
     3691            $slug = utf8_uri_encode( $decoded_slug, $length, true );
    36923692    }
    36933693
Note: See TracChangeset for help on using the changeset viewer.