Make WordPress Core

Changeset 52467


Ignore:
Timestamp:
01/06/2022 05:55:41 PM (3 years ago)
Author:
desrosj
Message:

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

Location:
branches/5.6
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/5.6

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

    r49765 r52467  
    16591659        while ( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
    16601660            foreach ( $rows as $row ) {
    1661                 $value = $row->option_value;
    1662                 if ( ! @unserialize( $value ) ) {
     1661                $value = maybe_unserialize( $row->option_value );
     1662                if ( $value === $row->option_value ) {
    16631663                    $value = stripslashes( $value );
    16641664                }
  • branches/5.6/src/wp-includes/class-wp-meta-query.php

    r48475 r52467  
    813813            $sibling_compare = strtoupper( $sibling['compare'] );
    814814            if ( in_array( $clause_compare, $compatible_compares, true ) && in_array( $sibling_compare, $compatible_compares, true ) ) {
    815                 $alias = $sibling['alias'];
     815                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    816816                break;
    817817            }
  • branches/5.6/src/wp-includes/class-wp-tax-query.php

    r48475 r52467  
    528528            // The sibling must both have compatible operator to share its alias.
    529529            if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators, true ) ) {
    530                 $alias = $sibling['alias'];
     530                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    531531                break;
    532532            }
     
    557557        }
    558558
    559         $query['terms'] = array_unique( (array) $query['terms'] );
     559        if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
     560            $query['terms'] = array_unique( (array) $query['terms'] );
     561        } else {
     562            $query['terms'] = wp_parse_id_list( $query['terms'] );
     563        }
    560564
    561565        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
  • branches/5.6/src/wp-includes/formatting.php

    r49513 r52467  
    11391139 *
    11401140 * @since 1.5.0
    1141  *
    1142  * @param string $utf8_string
    1143  * @param int    $length Max  length of the string
     1141 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
     1142 *
     1143 * @param string $utf8_string             String to encode.
     1144 * @param int    $length                  Max length of the string
     1145 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    11441146 * @return string String with Unicode encoded for URI.
    11451147 */
    1146 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     1148function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    11471149    $unicode        = '';
    11481150    $values         = array();
     
    11591161
    11601162        if ( $value < 128 ) {
    1161             if ( $length && ( $unicode_length >= $length ) ) {
     1163            $char                = chr( $value );
     1164            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     1165            $encoded_char_length = strlen( $encoded_char );
     1166            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    11621167                break;
    11631168            }
    1164             $unicode .= chr( $value );
    1165             $unicode_length++;
     1169            $unicode        .= $encoded_char;
     1170            $unicode_length += $encoded_char_length;
    11661171        } else {
    11671172            if ( count( $values ) == 0 ) {
  • branches/5.6/src/wp-includes/post.php

    r50052 r52467  
    47294729            $slug = substr( $slug, 0, $length );
    47304730        } else {
    4731             $slug = utf8_uri_encode( $decoded_slug, $length );
     4731            $slug = utf8_uri_encode( $decoded_slug, $length, true );
    47324732        }
    47334733    }
Note: See TracChangeset for help on using the changeset viewer.