From 6d963d60c6e33c273bd0e2ed2fea5a00ed5c48dc Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 20 May 2016 04:53:40 +0000 Subject: [PATCH] Emoji: Allow emoji in `blogname` and `blogdescription` on `utf8` installs. When the options table is set to `utf8` instead of `utf8mb4`, emoji will be stripped from the blog name and description when they're saved. Instead of stripping them, they can be encode as HTML entities. Fixes #36122. git-svn-id: https://develop.svn.wordpress.org/trunk@37469 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 4 ++++ tests/phpunit/tests/option/sanitize-option.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index ff0b6a4fd9..c2f08028c5 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3706,6 +3706,10 @@ function sanitize_option( $option, $value ) { case 'blogdescription': case 'blogname': $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value ); + if ( $value !== $original_value ) { + $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', wp_encode_emoji( $original_value ) ); + } + if ( is_wp_error( $value ) ) { $error = $value->get_error_message(); } else { diff --git a/tests/phpunit/tests/option/sanitize-option.php b/tests/phpunit/tests/option/sanitize-option.php index 4dd0942344..c4bea4554e 100644 --- a/tests/phpunit/tests/option/sanitize-option.php +++ b/tests/phpunit/tests/option/sanitize-option.php @@ -102,4 +102,21 @@ class Tests_Sanitize_Option extends WP_UnitTestCase { $this->assertSame( $expected, sanitize_option( 'upload_path', $provided ) ); } + /** + * @ticket #36122 + */ + public function test_emoji_in_blogname_and_description() { + global $wpdb; + + $value = "whee\xf0\x9f\x98\x88"; + + if ( 'utf8mb4' === $wpdb->get_col_charset( $wpdb->options, 'option_value' ) ) { + $expected = $value; + } else { + $expected = 'whee😈'; + } + + $this->assertSame( $expected, sanitize_option( 'blogname', $value ) ); + $this->assertSame( $expected, sanitize_option( 'blogdescription', $value ) ); + } }