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/formatting/Autop.php

    r31191 r33469  
    400400        $this->assertEquals( $expected, trim( wpautop( $content ) ) );
    401401    }
     402
     403    /**
     404     * Do not allow newlines within HTML elements to become mangled.
     405     *
     406     * @ticket 33106
     407     * @dataProvider data_element_sanity
     408     */
     409    function test_element_sanity( $input, $output ) {
     410        return $this->assertEquals( $output, wpautop( $input ) );
     411    }
     412
     413    function data_element_sanity() {
     414        return array(
     415            array(
     416                "Hello <a\nhref='world'>",
     417                "<p>Hello <a\nhref='world'></p>\n",
     418            ),
     419            array(
     420                "Hello <!-- a\nhref='world' -->",
     421                "<p>Hello <!-- a\nhref='world' --></p>\n",
     422            ),
     423/* Block elements inside comments will fail this test in all versions, it's not a regression.
     424            array(
     425                "Hello <!-- <hr> a\nhref='world' -->",
     426                "<p>Hello <!-- <hr> a\nhref='world' --></p>\n",
     427            ),
     428            array(
     429                "Hello <![CDATA[ <hr> a\nhttps://youtu.be/jgz0uSaOZbE\n ]]>",
     430                "<p>Hello <![CDATA[ <hr> a\nhttps://youtu.be/jgz0uSaOZbE\n ]]></p>\n",
     431            ),
     432*/
     433            array(
     434                "Hello <![CDATA[ a\nhttps://youtu.be/jgz0uSaOZbE\n ]]>",
     435                "<p>Hello <![CDATA[ a\nhttps://youtu.be/jgz0uSaOZbE\n ]]></p>\n",
     436            ),
     437            array(
     438                "Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> -->",
     439                "<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> --></p>\n",
     440            ),
     441            array(
     442                "Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a\n9 ]]>",
     443                "<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a\n9 ]]></p>\n",
     444            ),
     445        );
     446    }
     447   
    402448}
Note: See TracChangeset for help on using the changeset viewer.