From f9e1cf5de0566b7d5f5281f9bcef086abb9d062a Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 22 Apr 2016 07:07:03 +0000 Subject: [PATCH] Smilies: Move `convert_smilies` to happen later in the `the_content` filter. In particular, we want it to occur after shortcode handling. The smiley conversion routine doesn't have any concept of shortcode structure, so may inadvertantly replace a smiley with HTML inside a shortcode attribute, which will cause the shortcode to not be parsed correctly. Props Unyson for the initial suggested fix. Fixes #36306. git-svn-id: https://develop.svn.wordpress.org/trunk@37298 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/default-filters.php | 2 +- tests/phpunit/tests/shortcode.php | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 2ae86d88f5..5f5464e03f 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -130,7 +130,7 @@ add_filter( 'the_title', 'convert_chars' ); add_filter( 'the_title', 'trim' ); add_filter( 'the_content', 'wptexturize' ); -add_filter( 'the_content', 'convert_smilies' ); +add_filter( 'the_content', 'convert_smilies', 20 ); add_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'shortcode_unautop' ); add_filter( 'the_content', 'prepend_attachment' ); diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index 9f6a71d960..d28abf1ecd 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -4,7 +4,7 @@ */ class Tests_Shortcode extends WP_UnitTestCase { - protected $shortcodes = array( 'test-shortcode-tag', 'footag', 'bartag', 'baztag', 'dumptag', 'hyphen', 'hyphen-foo', 'hyphen-foo-bar', 'url' ); + protected $shortcodes = array( 'test-shortcode-tag', 'footag', 'bartag', 'baztag', 'dumptag', 'hyphen', 'hyphen-foo', 'hyphen-foo-bar', 'url', 'img' ); function setUp() { parent::setUp(); @@ -78,6 +78,16 @@ class Tests_Shortcode extends WP_UnitTestCase { return 'http://www.wordpress.org/'; } + function _shortcode_img( $atts ) { + $out = ' $v ) { + $out .= " $k=\"$v\""; + } + $out .= ' />'; + + return $out; + } + function test_noatts() { do_shortcode('[test-shortcode-tag /]'); $this->assertEquals( '', $this->atts ); @@ -657,4 +667,13 @@ EOF; $expected = "0 = =https://wordpress.org\n"; $this->assertEquals($expected, $out); } + + /** + * @ticket 36306 + */ + function test_smilies_arent_converted() { + $out = apply_filters( 'the_content', '[img alt="Hello :-) World"]' ); + $expected = "\"Hello\n"; + $this->assertEquals( $expected, $out ); + } }