From 4bad064c2494a54091cf9f43601ef5819e7c9dd1 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 14 Jul 2017 11:49:34 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@41045 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 4 +--- tests/phpunit/tests/formatting/Emoji.php | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index bac3ad787d..c708a26e98 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -5290,9 +5290,7 @@ function wp_emoji_regex( $type = 'codepoints' ) { // If we're using a PCRE version that doesn't support Unicode, return a loose match regex. if ( 'codepoints' === $type && ( ! defined( 'PCRE_VERSION' ) || version_compare( PCRE_VERSION, '8.32', '<=' ) ) ) { return '/( - \xE2\x98[\x80-\xFF] # Symbols - | \xE2\x99[\x00-\xFF] - | [\xE3-\xED][\x00-\xFF]{2} + \xE2\x99[\x80-\x82] # Male and female symbols | [\x23\x30-\x39]\xE2\x83\xA3 # Digits | \xF0\x9F[\x85-\x88][\xA6-\xBF] # Enclosed characters | \xF0\x9F[\x8C-\x97][\x80-\xBF] # Misc diff --git a/tests/phpunit/tests/formatting/Emoji.php b/tests/phpunit/tests/formatting/Emoji.php index cc98b4290d..856f02a711 100644 --- a/tests/phpunit/tests/formatting/Emoji.php +++ b/tests/phpunit/tests/formatting/Emoji.php @@ -101,7 +101,6 @@ class Tests_Formatting_Emoji extends WP_UnitTestCase { '🧚', '🧚', ), - ); } @@ -114,7 +113,7 @@ class Tests_Formatting_Emoji extends WP_UnitTestCase { } public function data_wp_staticize_emoji() { - return array( + $data = array( array( // Not emoji '’', @@ -123,20 +122,27 @@ class Tests_Formatting_Emoji extends WP_UnitTestCase { array( // Simple emoji '🙂', - '🙂', + '', ), array( // Skin tone, gender, ZWJ, emoji selector '👮🏼‍♀️', - '👮🏼‍♀️', + '', ), array( // Unicode 10 '🧚', - '🧚', + '', ), - ); + + // Older versions of PHP don't html_entity_decode() emoji, so we need to make sure they're testing in the expected form. + foreach ( $data as $key => $datum ) { + $emoji = html_entity_decode( wp_encode_emoji( $datum[0] ) ); + $data[ $key ][1] = str_replace( 'alt=""', 'alt="' . $emoji . '"', $datum[1] ); + } + + return $data; } /**