Make WordPress Core


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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2

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