Make WordPress Core


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

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

Location:
branches/5.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

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

    r47643 r52469  
    11581158 *
    11591159 * @since 1.5.0
    1160  *
    1161  * @param string $utf8_string
    1162  * @param int    $length Max  length of the string
     1160 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
     1161 *
     1162 * @param string $utf8_string             String to encode.
     1163 * @param int    $length                  Max length of the string
     1164 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    11631165 * @return string String with Unicode encoded for URI.
    11641166 */
    1165 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     1167function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    11661168    $unicode        = '';
    11671169    $values         = array();
     
    11781180
    11791181        if ( $value < 128 ) {
    1180             if ( $length && ( $unicode_length >= $length ) ) {
     1182            $char                = chr( $value );
     1183            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     1184            $encoded_char_length = strlen( $encoded_char );
     1185            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    11811186                break;
    11821187            }
    1183             $unicode .= chr( $value );
    1184             $unicode_length++;
     1188            $unicode        .= $encoded_char;
     1189            $unicode_length += $encoded_char_length;
    11851190        } else {
    11861191            if ( count( $values ) == 0 ) {
Note: See TracChangeset for help on using the changeset viewer.