Make WordPress Core


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

Grouped backports to the 4.0 branch.

  • Query: Improve sanitization within WP_Tax_Query.
  • Upgrade/Install: Avoid using unserialize() unnecessarily.
  • Formatting: Correctly encode ASCII characters in post slugs.

Merges [52454,52456-52457] to the 4.0 branch.
Props vortfu, dd32, ehtis, zieladam, whyisjake, xknown, peterwilsoncc, desrosj, iandunn.

Location:
branches/4.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

  • branches/4.0/src/wp-includes/formatting.php

    r47659 r52483  
    859859 *
    860860 * @since 1.5.0
     861 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
    861862 *
    862863 * @param string $utf8_string
    863864 * @param int $length Max length of the string
     865 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    864866 * @return string String with Unicode encoded for URI.
    865867 */
    866 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     868function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    867869    $unicode = '';
    868870    $values = array();
     
    879881
    880882        if ( $value < 128 ) {
    881             if ( $length && ( $unicode_length >= $length ) )
     883            $char                = chr( $value );
     884            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     885            $encoded_char_length = strlen( $encoded_char );
     886            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    882887                break;
    883             $unicode .= chr($value);
    884             $unicode_length++;
     888            }
     889            $unicode        .= $encoded_char;
     890            $unicode_length += $encoded_char_length;
    885891        } else {
    886892            if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
Note: See TracChangeset for help on using the changeset viewer.