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.


git-svn-id: https://develop.svn.wordpress.org/trunk@33469 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-07-28 23:02:04 +00:00
parent 1558be9dfa
commit 4f814ec9ae
5 changed files with 225 additions and 46 deletions
+46
View File
@@ -399,4 +399,50 @@ Paragraph two.';
$this->assertEquals( $expected, trim( wpautop( $content ) ) );
}
/**
* Do not allow newlines within HTML elements to become mangled.
*
* @ticket 33106
* @dataProvider data_element_sanity
*/
function test_element_sanity( $input, $output ) {
return $this->assertEquals( $output, wpautop( $input ) );
}
function data_element_sanity() {
return array(
array(
"Hello <a\nhref='world'>",
"<p>Hello <a\nhref='world'></p>\n",
),
array(
"Hello <!-- a\nhref='world' -->",
"<p>Hello <!-- a\nhref='world' --></p>\n",
),
/* Block elements inside comments will fail this test in all versions, it's not a regression.
array(
"Hello <!-- <hr> a\nhref='world' -->",
"<p>Hello <!-- <hr> a\nhref='world' --></p>\n",
),
array(
"Hello <![CDATA[ <hr> a\nhttps://youtu.be/jgz0uSaOZbE\n ]]>",
"<p>Hello <![CDATA[ <hr> a\nhttps://youtu.be/jgz0uSaOZbE\n ]]></p>\n",
),
*/
array(
"Hello <![CDATA[ a\nhttps://youtu.be/jgz0uSaOZbE\n ]]>",
"<p>Hello <![CDATA[ a\nhttps://youtu.be/jgz0uSaOZbE\n ]]></p>\n",
),
array(
"Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> -->",
"<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> --></p>\n",
),
array(
"Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a\n9 ]]>",
"<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a\n9 ]]></p>\n",
),
);
}
}