WordPress.org

Make WordPress Core

Ticket #44278: 44278.3.diff

File 44278.3.diff, 3.4 KB (added by birgire, 13 months ago)
  • src/wp-includes/formatting.php

    diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
    index a0438e9..2cd2212 100644
    function translate_smiley( $matches ) { 
    31413141/**
    31423142 * Convert text equivalent of smilies to images.
    31433143 *
    3144  * Will only convert smilies if the option 'use_smilies' is true and the global
     3144 * Will only convert smilies if the option `'use_smilies'` is `true` and the global
    31453145 * used in the function isn't empty.
    31463146 *
    31473147 * @since 0.71
    function convert_smilies( $text ) { 
    31553155        global $wp_smiliessearch;
    31563156        $output = '';
    31573157        if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
    3158                 // HTML loop taken from texturize function, could possible be consolidated
    3159                 $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
    3160                 $stop    = count( $textarr );// loop stuff
     3158                // HTML loop taken from texturize function, could possible be consolidated.
     3159                $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Capture the tags as well as in between.
     3160                $stop    = count( $textarr );// Loop stuff.
    31613161
    3162                 // Ignore proessing of specific tags
     3162                // Ignore processing of specific tags.
    31633163                $tags_to_ignore       = 'code|pre|style|script|textarea';
    31643164                $ignore_block_element = '';
    31653165
    31663166                for ( $i = 0; $i < $stop; $i++ ) {
    31673167                        $content = $textarr[ $i ];
    31683168
    3169                         // If we're in an ignore block, wait until we find its closing tag
    3170                         if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) {
     3169                        // If we're in an ignore block, wait until we find its closing tag.
     3170                        if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) {
    31713171                                $ignore_block_element = $matches[1];
    31723172                        }
    31733173
    3174                         // If it's not a tag and not in ignore block
     3174                        // If it's not a tag and not in ignore block.
    31753175                        if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
    31763176                                $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
    31773177                        }
    31783178
    3179                         // did we exit ignore block
     3179                        // Did we exit ignore block.
    31803180                        if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) {
    31813181                                $ignore_block_element = '';
    31823182                        }
    function convert_smilies( $text ) { 
    31843184                        $output .= $content;
    31853185                }
    31863186        } else {
    3187                 // return default text.
     3187                // Return default text.
    31883188                $output = $text;
    31893189        }
    31903190        return $output;
  • tests/phpunit/tests/formatting/Smilies.php

    diff --git tests/phpunit/tests/formatting/Smilies.php tests/phpunit/tests/formatting/Smilies.php
    index d1fd3af..114fd04 100644
    class Tests_Formatting_Smilies extends WP_UnitTestCase { 
    194194        }
    195195
    196196        /**
     197         * Conversion of Smilies should be ignored in pre-determined tags
     198         * (pre, code, script, style and textarea) with attributes.
     199         *
     200         * @ticket 44278
     201         * @dataProvider get_smilies_ignore_tags
     202         */
     203        public function test_smilies_in_tags_with_attributes_should_be_ignored( $element ) {
     204                update_option( 'use_smilies', 1 );
     205                smilies_init();
     206
     207                $expected = "<$element class=\"test\">:grin: :)</$element>";
     208                $actual   = convert_smilies( $expected );
     209
     210                update_option( 'use_smilies', 0 );
     211
     212                $this->assertSame( $expected, $actual );
     213        }
     214
     215        /**
    197216         * Validate Combinations of Smilies separated by single space
    198217         * are converted correctly
    199218         *