Make WordPress Core


Ignore:
Timestamp:
07/28/2015 11:02:04 PM (9 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/class-wp-embed.php

    r33359 r33469  
    130130     */
    131131    public function shortcode( $attr, $url = '' ) {
     132        // This filter can be used to output custom HTML instead of allowing oEmbed to run.
     133        $custom = apply_filters( 'wp_embed_shortcode_custom', false, $attr, $url );
     134        if ( false !== $custom ) {
     135            return $custom;
     136        }
     137       
    132138        $post = get_post();
    133139
     
    319325     */
    320326    public function autoembed( $content ) {
    321         // Strip newlines from all elements.
    322         $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) );
     327        // Replace line breaks from all HTML elements with placeholders.
     328        $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );
    323329
    324330        // Find URLs that are on their own line.
    325         return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
     331        $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
     332
     333        // Put the line breaks back.
     334        return str_replace( '<!-- wp-line-break -->', "\n", $content );
    326335    }
    327336
Note: See TracChangeset for help on using the changeset viewer.