mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-03 08:40:10 +00:00
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:
@@ -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",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -585,4 +585,115 @@ VIDEO;
|
||||
$this->assertEquals( 'This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $post->post_excerpt );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33016
|
||||
*/
|
||||
function test_multiline_cdata() {
|
||||
global $wp_embed;
|
||||
|
||||
$content = <<<EOF
|
||||
<script>// <![CDATA[
|
||||
_my_function('data');
|
||||
// ]]>
|
||||
</script>
|
||||
EOF;
|
||||
|
||||
$result = $wp_embed->autoembed( $content );
|
||||
$this->assertEquals( $content, $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33016
|
||||
*/
|
||||
function test_multiline_comment() {
|
||||
global $wp_embed;
|
||||
|
||||
$content = <<<EOF
|
||||
<script><!--
|
||||
my_function();
|
||||
// --> </script>
|
||||
EOF;
|
||||
|
||||
$result = $wp_embed->autoembed( $content );
|
||||
$this->assertEquals( $content, $result );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ticket 33016
|
||||
*/
|
||||
function test_multiline_comment_with_embeds() {
|
||||
$content = <<<EOF
|
||||
Start.
|
||||
[embed]http://www.youtube.com/embed/TEST01YRHA0[/embed]
|
||||
<script><!--
|
||||
my_function();
|
||||
// --> </script>
|
||||
http://www.youtube.com/embed/TEST02YRHA0
|
||||
[embed]http://www.example.com/embed/TEST03YRHA0[/embed]
|
||||
http://www.example.com/embed/TEST04YRHA0
|
||||
Stop.
|
||||
EOF;
|
||||
|
||||
$expected = <<<EOF
|
||||
<p>Start.<br />
|
||||
https://youtube.com/watch?v=TEST01YRHA0<br />
|
||||
<script><!--
|
||||
my_function();
|
||||
// --> </script><br />
|
||||
https://youtube.com/watch?v=TEST02YRHA0<br />
|
||||
<a href="http://www.example.com/embed/TEST03YRHA0">http://www.example.com/embed/TEST03YRHA0</a><br />
|
||||
http://www.example.com/embed/TEST04YRHA0<br />
|
||||
Stop.</p>
|
||||
|
||||
EOF;
|
||||
|
||||
$result = apply_filters( 'the_content', $content );
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33016
|
||||
*/
|
||||
function filter_wp_embed_shortcode_custom( $custom, $attr, $url ) {
|
||||
if ( 'https://www.example.com/?video=1' == $url ) {
|
||||
$custom = "<iframe src='$url'></iframe>";
|
||||
}
|
||||
return $custom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33016
|
||||
*/
|
||||
function test_oembed_explicit_media_link() {
|
||||
global $wp_embed;
|
||||
add_filter( 'wp_embed_shortcode_custom', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 3 );
|
||||
|
||||
$content = <<<EOF
|
||||
https://www.example.com/?video=1
|
||||
EOF;
|
||||
|
||||
$expected = <<<EOF
|
||||
<iframe src='https://www.example.com/?video=1'></iframe>
|
||||
EOF;
|
||||
|
||||
$result = $wp_embed->autoembed( $content );
|
||||
$this->assertEquals( $expected, $result );
|
||||
|
||||
$content = <<<EOF
|
||||
<a href="https://www.example.com/?video=1">https://www.example.com/?video=1</a>
|
||||
<script>// <![CDATA[
|
||||
_my_function('data');
|
||||
myvar = 'Hello world
|
||||
https://www.example.com/?video=1
|
||||
don't break this';
|
||||
// ]]>
|
||||
</script>
|
||||
EOF;
|
||||
|
||||
$result = $wp_embed->autoembed( $content );
|
||||
$this->assertEquals( $content, $result );
|
||||
|
||||
remove_filter( 'wp_embed_shortcode_custom', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user