From d2a011c666b9975671c1f4ea3e87f5a19c14dd95 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 3 Oct 2017 09:56:45 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@41702 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 12 ++++++++++-- tests/phpunit/tests/formatting/Emoji.php | 12 +++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index bcdaec423d..54d12c6398 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -5113,7 +5113,11 @@ function wp_encode_emoji( $content ) { $emoji = _wp_emoji_list( 'partials' ); foreach ( $emoji as $emojum ) { - $emoji_char = html_entity_decode( $emojum ); + if ( version_compare( phpversion(), '5.4', '<' ) ) { + $emoji_char = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' ); + } else { + $emoji_char = html_entity_decode( $emojum ); + } if ( false !== strpos( $content, $emoji_char ) ) { $content = preg_replace( "/$emoji_char/", $emojum, $content ); } @@ -5151,7 +5155,11 @@ function wp_staticize_emoji( $text ) { $possible_emoji = array(); foreach( $emoji as $emojum ) { if ( false !== strpos( $text, $emojum ) ) { - $possible_emoji[ $emojum ] = html_entity_decode( $emojum ); + if ( version_compare( phpversion(), '5.4', '<' ) ) { + $possible_emoji[ $emojum ] = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' ); + } else { + $possible_emoji[ $emojum ] = html_entity_decode( $emojum ); + } } } diff --git a/tests/phpunit/tests/formatting/Emoji.php b/tests/phpunit/tests/formatting/Emoji.php index 6bc16db592..d508ac337c 100644 --- a/tests/phpunit/tests/formatting/Emoji.php +++ b/tests/phpunit/tests/formatting/Emoji.php @@ -122,26 +122,20 @@ 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; }