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/tests/phpunit/tests/media.php

    r32930 r33469  
    586586    }
    587587
     588    /**
     589     * @ticket 33016
     590     */
     591    function test_multiline_cdata() {
     592        global $wp_embed;
     593
     594        $content = <<<EOF
     595<script>// <![CDATA[
     596_my_function('data');
     597// ]]>
     598</script>
     599EOF;
     600
     601        $result = $wp_embed->autoembed( $content );
     602        $this->assertEquals( $content, $result );
     603    }
     604
     605    /**
     606     * @ticket 33016
     607     */
     608    function test_multiline_comment() {
     609        global $wp_embed;
     610
     611        $content = <<<EOF
     612<script><!--
     613my_function();
     614// --> </script>
     615EOF;
     616
     617        $result = $wp_embed->autoembed( $content );
     618        $this->assertEquals( $content, $result );
     619    }
     620
     621
     622    /**
     623     * @ticket 33016
     624     */
     625    function test_multiline_comment_with_embeds() {
     626        $content = <<<EOF
     627Start.
     628[embed]http://www.youtube.com/embed/TEST01YRHA0[/embed]
     629<script><!--
     630my_function();
     631// --> </script>
     632http://www.youtube.com/embed/TEST02YRHA0
     633[embed]http://www.example.com/embed/TEST03YRHA0[/embed]
     634http://www.example.com/embed/TEST04YRHA0
     635Stop.
     636EOF;
     637
     638        $expected = <<<EOF
     639<p>Start.<br />
     640https://youtube.com/watch?v=TEST01YRHA0<br />
     641<script><!--
     642my_function();
     643// --> </script><br />
     644https://youtube.com/watch?v=TEST02YRHA0<br />
     645<a href="http://www.example.com/embed/TEST03YRHA0">http://www.example.com/embed/TEST03YRHA0</a><br />
     646http://www.example.com/embed/TEST04YRHA0<br />
     647Stop.</p>
     648
     649EOF;
     650
     651        $result = apply_filters( 'the_content', $content );
     652        $this->assertEquals( $expected, $result );
     653    }
     654
     655    /**
     656     * @ticket 33016
     657     */
     658    function filter_wp_embed_shortcode_custom( $custom, $attr, $url ) {
     659        if ( 'https://www.example.com/?video=1' == $url ) {
     660            $custom = "<iframe src='$url'></iframe>";
     661        }
     662        return $custom;
     663    }
     664
     665    /**
     666     * @ticket 33016
     667     */
     668    function test_oembed_explicit_media_link() {
     669        global $wp_embed;
     670        add_filter( 'wp_embed_shortcode_custom', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 3 );
     671
     672        $content = <<<EOF
     673https://www.example.com/?video=1
     674EOF;
     675
     676        $expected = <<<EOF
     677<iframe src='https://www.example.com/?video=1'></iframe>
     678EOF;
     679
     680        $result = $wp_embed->autoembed( $content );
     681        $this->assertEquals( $expected, $result );
     682
     683        $content = <<<EOF
     684<a href="https://www.example.com/?video=1">https://www.example.com/?video=1</a>
     685<script>// <![CDATA[
     686_my_function('data');
     687myvar = 'Hello world
     688https://www.example.com/?video=1
     689don't break this';
     690// ]]>
     691</script>
     692EOF;
     693
     694        $result = $wp_embed->autoembed( $content );
     695        $this->assertEquals( $content, $result );
     696
     697        remove_filter( 'wp_embed_shortcode_custom', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
     698    }
    588699}
Note: See TracChangeset for help on using the changeset viewer.