Make WordPress Core

Changeset 41045


Ignore:
Timestamp:
07/14/2017 11:49:34 AM (9 years ago)
Author:
pento
Message:

Emoji: Fix some failing unit tests in PHP 5.2 and 5.3.

  • Older versions of PHP don't know how to html_entity_decode() emoji.
  • The fall back regex was a little too broad, catching characters that aren't emoji.

See #35293.

Location:
trunk
Files:
2 edited

Legend:

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

    r41043 r41045  
    52915291        if ( 'codepoints' === $type && ( ! defined( 'PCRE_VERSION' ) || version_compare( PCRE_VERSION, '8.32', '<=' ) ) ) {
    52925292                return '/(
    5293                      \xE2\x98[\x80-\xFF]            # Symbols
    5294                    | \xE2\x99[\x00-\xFF]
    5295                    | [\xE3-\xED][\x00-\xFF]{2}
     5293                     \xE2\x99[\x80-\x82]            # Male and female symbols
    52965294                   | [\x23\x30-\x39]\xE2\x83\xA3    # Digits
    52975295                   | \xF0\x9F[\x85-\x88][\xA6-\xBF] # Enclosed characters
  • trunk/tests/phpunit/tests/formatting/Emoji.php

    r41043 r41045  
    102102                                '&#x1f9da;',
    103103                        ),
    104 
    105104                );
    106105        }
     
    115114
    116115        public function data_wp_staticize_emoji() {
    117                 return array(
     116                $data = array(
    118117                        array(
    119118                                // Not emoji
     
    124123                                // Simple emoji
    125124                                '🙂',
    126                                 '<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;" />',
    127126                        ),
    128127                        array(
    129128                                // Skin tone, gender, ZWJ, emoji selector
    130129                                '👮🏼‍♀️',
    131                                 '<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;" />',
    132131                        ),
    133132                        array(
    134133                                // Unicode 10
    135134                                '🧚',
    136                                 '<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;" />',
    137136                        ),
     137                );
    138138
    139                 );
     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                }
     144
     145                return $data;
    140146        }
    141147
Note: See TracChangeset for help on using the changeset viewer.