Make WordPress Core

Changeset 52481


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

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

Location:
branches/4.2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2

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

    r37939 r52481  
    11641164        while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
    11651165            foreach( $rows as $row ) {
    1166                 $value = $row->option_value;
    1167                 if ( !@unserialize( $value ) )
     1166                $value = maybe_unserialize( $row->option_value );
     1167                if ( $value === $row->option_value )
    11681168                    $value = stripslashes( $value );
    11691169                if ( $value !== $row->option_value ) {
  • branches/4.2/src/wp-includes/formatting.php

    r47657 r52481  
    909909 *
    910910 * @since 1.5.0
     911 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
    911912 *
    912913 * @param string $utf8_string
    913914 * @param int $length Max length of the string
     915 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    914916 * @return string String with Unicode encoded for URI.
    915917 */
    916 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     918function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    917919    $unicode = '';
    918920    $values = array();
     
    929931
    930932        if ( $value < 128 ) {
    931             if ( $length && ( $unicode_length >= $length ) )
     933            $char                = chr( $value );
     934            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     935            $encoded_char_length = strlen( $encoded_char );
     936            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    932937                break;
    933             $unicode .= chr($value);
    934             $unicode_length++;
     938            }
     939            $unicode        .= $encoded_char;
     940            $unicode_length += $encoded_char_length;
    935941        } else {
    936942            if ( count( $values ) == 0 ) {
  • branches/4.2/src/wp-includes/meta.php

    r49404 r52481  
    15491549            $sibling_compare = strtoupper( $sibling['compare'] );
    15501550            if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) {
    1551                 $alias = $sibling['alias'];
     1551                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    15521552                break;
    15531553            }
  • branches/4.2/src/wp-includes/post.php

    r43400 r52481  
    38263826            $slug = substr( $slug, 0, $length );
    38273827        else
    3828             $slug = utf8_uri_encode( $decoded_slug, $length );
     3828            $slug = utf8_uri_encode( $decoded_slug, $length, true );
    38293829    }
    38303830
  • branches/4.2/src/wp-includes/taxonomy.php

    r37137 r52481  
    11561156            // The sibling must both have compatible operator to share its alias.
    11571157            if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
    1158                 $alias = $sibling['alias'];
     1158                $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
    11591159                break;
    11601160            }
     
    11861186        }
    11871187
    1188         $query['terms'] = array_unique( (array) $query['terms'] );
     1188        if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
     1189            $query['terms'] = array_unique( (array) $query['terms'] );
     1190        } else {
     1191            $query['terms'] = wp_parse_id_list( $query['terms'] );
     1192        }
    11891193
    11901194        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
Note: See TracChangeset for help on using the changeset viewer.