WordPress.org

Make WordPress Core

Changeset 28852


Ignore:
Timestamp:
06/26/2014 05:14:47 PM (6 years ago)
Author:
wonderboymusic
Message:

Use less greedy regex in wptexturize(). Adds unit tests.

Props miqrogroove.
See #28564.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r28831 r28852  
    199199        .       '.+?--\s*>' // Find end of comment
    200200        .   '|'
    201         .       '.+?>'      // Find end of element
     201        .       '[^>]+>'    // Find end of element
    202202        .   ')'
    203203        . '|'
     
    207207        .       '[^\[\]<>]' // Shortcodes do not contain other shortcodes.
    208208        .   '|'
    209         .       '<.+?>'     // HTML elements permitted. Prevents matching ] before >.
     209        .       '<[^>]+>'   // HTML elements permitted. Prevents matching ] before >.
    210210        .   ')+'
    211211        .   '\]'        // Find end of shortcode.
     
    225225            }
    226226
    227         } elseif ( '[' === $first && 1 === preg_match( '/^\[(?:[^\[\]<>]|<.+?>)+\]$/', $curl ) ) {
     227        } elseif ( '[' === $first && 1 === preg_match( '/^\[(?:[^\[\]<>]|<[^>]+>)+\]$/', $curl ) ) {
    228228            // This is a shortcode delimeter.
    229229
    230230            _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
    231231
    232         } elseif ( '[' === $first && 1 === preg_match( '/^\[\[?(?:[^\[\]<>]|<.+?>)+\]\]?$/', $curl ) ) {
     232        } elseif ( '[' === $first && 1 === preg_match( '/^\[\[?(?:[^\[\]<>]|<[^>]+>)+\]\]?$/', $curl ) ) {
    233233            // This is an escaped shortcode delimeter.
    234234
  • trunk/tests/phpunit/tests/formatting/WPTexturize.php

    r28831 r28852  
    13051305                'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word', // Ensure we are not corrupting image URLs.
    13061306                'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word',
     1307            ),
     1308            array(
     1309                '[ do texturize "[quote]" here ]',
     1310                '[ do texturize &#8220;[quote]&#8221; here ]',
     1311            ),
     1312            array(
     1313                '[ regex catches this <a href="[quote]">here</a> ]',
     1314                '[ regex catches this <a href="[quote]">here</a> ]',
     1315            ),
     1316            array(
     1317                '[ but also catches the <b>styled "[quote]" here</b> ]',
     1318                '[ but also catches the <b>styled &#8220;[quote]&#8221; here</b> ]',
     1319            ),
     1320            array(
     1321                '[Let\'s get crazy<input>[plugin code="<a href=\'?a[]=100\'>hello</a>"]</input>world]',
     1322                '[Let&#8217;s get crazy<input>[plugin code="<a href=\'?a[]=100\'>hello</a>"]</input>world]',
    13071323            ),
    13081324        );
Note: See TracChangeset for help on using the changeset viewer.