Make WordPress Core


Ignore:
Timestamp:
01/06/2022 06:23:29 PM (3 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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

  • 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;
Note: See TracChangeset for help on using the changeset viewer.