Make WordPress Core

Changeset 41702


Ignore:
Timestamp:
10/03/2017 09:56:45 AM (7 years ago)
Author:
pento
Message:

Emoji: Fix incorrect emoji encoding in PHP < 5.4.

[41701] included a bug with PHP < 5.4. Prior to then, html_entity_decode() decoded into ISO-8859-1, when we actually need it to use UTF-8.

Fixes #35293.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r41701 r41702  
    51145114
    51155115    foreach ( $emoji as $emojum ) {
    5116         $emoji_char = html_entity_decode( $emojum );
     5116        if ( version_compare( phpversion(), '5.4', '<' ) ) {
     5117            $emoji_char = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
     5118        } else {
     5119            $emoji_char = html_entity_decode( $emojum );
     5120        }
    51175121        if ( false !== strpos( $content, $emoji_char ) ) {
    51185122            $content = preg_replace( "/$emoji_char/", $emojum, $content );
     
    51525156    foreach( $emoji as $emojum ) {
    51535157        if ( false !== strpos( $text, $emojum ) ) {
    5154             $possible_emoji[ $emojum ] = html_entity_decode( $emojum );
     5158            if ( version_compare( phpversion(), '5.4', '<' ) ) {
     5159                $possible_emoji[ $emojum ] = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
     5160            } else {
     5161                $possible_emoji[ $emojum ] = html_entity_decode( $emojum );
     5162            }
    51555163        }
    51565164    }
  • trunk/tests/phpunit/tests/formatting/Emoji.php

    r41701 r41702  
    123123                // Simple emoji
    124124                '🙂',
    125                 '<img src="' . $this->png_cdn . '1f642.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     125                '<img src="' . $this->png_cdn . '1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    126126            ),
    127127            array(
    128128                // Skin tone, gender, ZWJ, emoji selector
    129129                '👮🏼‍♀️',
    130                 '<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     130                '<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="👮🏼‍♀️" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    131131            ),
    132132            array(
    133133                // Unicode 10
    134134                '🧚',
    135                 '<img src="' . $this->png_cdn . '1f9da.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     135                '<img src="' . $this->png_cdn . '1f9da.png" alt="🧚" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    136136            ),
    137137        );
    138 
    139         // Older versions of PHP don't html_entity_decode() emoji, so we need to make sure they're testing in the expected form.
    140         foreach ( $data as $key => $datum ) {
    141             $emoji = html_entity_decode( wp_encode_emoji( $datum[0] ) );
    142             $data[ $key ][1] = str_replace( 'alt=""', 'alt="' . $emoji . '"', $datum[1] );
    143         }
    144138
    145139        return $data;
Note: See TracChangeset for help on using the changeset viewer.