Make WordPress Core

Changeset 52464


Ignore:
Timestamp:
01/06/2022 05:34:05 PM (11 months ago)
Author:
desrosj
Message:

Formatting: Correctly encode ASCII characters in post slugs.

Merges [52457] to the 5.9 branch.
Props zieladam, whyisjake, xknown, peterwilsoncc, desrosj, iandunn.

Location:
branches/5.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.9

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

    r52370 r52464  
    11391139 *
    11401140 * @since 1.5.0
    1141  *
    1142  * @param string $utf8_string
    1143  * @param int    $length Max  length of the string
     1141 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
     1142 *
     1143 * @param string $utf8_string             String to encode.
     1144 * @param int    $length                  Max length of the string
     1145 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
    11441146 * @return string String with Unicode encoded for URI.
    11451147 */
    1146 function utf8_uri_encode( $utf8_string, $length = 0 ) {
     1148function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
    11471149    $unicode        = '';
    11481150    $values         = array();
     
    11591161
    11601162        if ( $value < 128 ) {
    1161             if ( $length && ( $unicode_length >= $length ) ) {
     1163            $char                = chr( $value );
     1164            $encoded_char        = $encode_ascii_characters ? rawurlencode( $char ) : $char;
     1165            $encoded_char_length = strlen( $encoded_char );
     1166            if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
    11621167                break;
    11631168            }
    1164             $unicode .= chr( $value );
    1165             $unicode_length++;
     1169            $unicode        .= $encoded_char;
     1170            $unicode_length += $encoded_char_length;
    11661171        } else {
    11671172            if ( count( $values ) == 0 ) {
  • branches/5.9/src/wp-includes/post.php

    r52400 r52464  
    51435143            $slug = substr( $slug, 0, $length );
    51445144        } else {
    5145             $slug = utf8_uri_encode( $decoded_slug, $length );
     5145            $slug = utf8_uri_encode( $decoded_slug, $length, true );
    51465146        }
    51475147    }
Note: See TracChangeset for help on using the changeset viewer.