mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-07 02:30: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:
@@ -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