WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/28/2015 11:02:04 PM (5 years ago)
Author:
wonderboymusic
Message:

Protect newlines inside of CDATA. This was breaking things, notably inline JS that used comments for HTML standards compat.

  • Tokenize newlines in WP_Embed::autoembed() before running ->autoembed_callback()
  • Tokenize newlines with placeholders in wpautop()
  • Introduce wp_html_split() to DRY the RegEx from wp_replace_in_html_tags() and do_shortcodes_in_html_tags()

Adds unit tests.

Props miqrogroove, kitchin, azaozz.
Fixes #33106.

File:
1 edited

Legend:

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

    r33359 r33469  
    334334   
    335335    $pattern = get_shortcode_regex();
    336 
    337     $comment_regex =
    338           '!'           // Start of comment, after the <.
    339         . '(?:'         // Unroll the loop: Consume everything until --> is found.
    340         .     '-(?!->)' // Dash not followed by end of comment.
    341         .     '[^\-]*+' // Consume non-dashes.
    342         . ')*+'         // Loop possessively.
    343         . '(?:-->)?';   // End of comment. If not found, match all input.
    344 
    345     $regex =
    346           '/('                   // Capture the entire match.
    347         .     '<'                // Find start of element.
    348         .     '(?(?=!--)'        // Is this a comment?
    349         .         $comment_regex // Find end of comment.
    350         .     '|'
    351         .         '[^>]*>?'      // Find end of element. If not found, match all input.
    352         .     ')'
    353         . ')/s';
    354 
    355     $textarr = preg_split( $regex, $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
     336    $textarr = wp_html_split( $content );
    356337
    357338    foreach ( $textarr as &$element ) {
    358         if ( '<' !== $element[0] ) {
     339        if ( '' == $element || '<' !== $element[0] ) {
    359340            continue;
    360341        }
     
    371352        }
    372353
    373         if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) ) {
     354        if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) {
    374355            // Encode all [ and ] chars.
    375356            $element = strtr( $element, $trans );
Note: See TracChangeset for help on using the changeset viewer.