<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[33469] trunk: Protect newlines inside of `CDATA`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/33469">33469</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/33469","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>wonderboymusic</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-07-28 23:02:04 +0000 (Tue, 28 Jul 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/33106">#33106</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpembedphp">trunk/src/wp-includes/class-wp-embed.php</a></li>
<li><a href="#trunksrcwpincludesformattingphp">trunk/src/wp-includes/formatting.php</a></li>
<li><a href="#trunksrcwpincludesshortcodesphp">trunk/src/wp-includes/shortcodes.php</a></li>
<li><a href="#trunktestsphpunittestsformattingAutopphp">trunk/tests/phpunit/tests/formatting/Autop.php</a></li>
<li><a href="#trunktestsphpunittestsmediaphp">trunk/tests/phpunit/tests/media.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpembedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-embed.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-embed.php 2015-07-28 22:06:52 UTC (rev 33468)
+++ trunk/src/wp-includes/class-wp-embed.php 2015-07-28 23:02:04 UTC (rev 33469)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -129,6 +129,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * `->maybe_make_link()` can return false on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function shortcode( $attr, $url = '' ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // This filter can be used to output custom HTML instead of allowing oEmbed to run.
+ $custom = apply_filters( 'wp_embed_shortcode_custom', false, $attr, $url );
+ if ( false !== $custom ) {
+ return $custom;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $post = get_post();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $url ) && ! empty( $attr['src'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -318,11 +324,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string Potentially modified $content.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function autoembed( $content ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Strip newlines from all elements.
- $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Replace line breaks from all HTML elements with placeholders.
+ $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Find URLs that are on their own line.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
+
+ // Put the line breaks back.
+ return str_replace( '<!-- wp-line-break -->', "\n", $content );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpincludesformattingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/formatting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/formatting.php 2015-07-28 22:06:52 UTC (rev 33468)
+++ trunk/src/wp-includes/formatting.php 2015-07-28 23:02:04 UTC (rev 33469)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -504,8 +504,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Standardize newline characters to "\n".
</span><span class="cx" style="display: block; padding: 0 10px"> $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Strip newlines from all elements.
- $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Find newlines in all elements and add placeholders.
+ $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Collapse line breaks before and after <option> elements so they don't get autop'd.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( strpos( $pee, '<option' ) !== false ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -592,10 +592,60 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( !empty($pre_tags) )
</span><span class="cx" style="display: block; padding: 0 10px"> $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Restore newlines in all elements.
+ $pee = str_replace( " <!-- wpnl --> ", "\n", $pee );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $pee;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Separate HTML elements and comments from the text.
+ *
+ * @since 4.2.4
+ *
+ * @param string $input The text which has to be formatted.
+ * @return array The formatted text.
+ */
+function wp_html_split( $input ) {
+ static $regex;
+
+ if ( ! isset( $regex ) ) {
+ $comments =
+ '!' // Start of comment, after the <.
+ . '(?:' // Unroll the loop: Consume everything until --> is found.
+ . '-(?!->)' // Dash not followed by end of comment.
+ . '[^\-]*+' // Consume non-dashes.
+ . ')*+' // Loop possessively.
+ . '(?:-->)?'; // End of comment. If not found, match all input.
+
+ $cdata =
+ '!\[CDATA\[' // Start of comment, after the <.
+ . '[^\]]*+' // Consume non-].
+ . '(?:' // Unroll the loop: Consume everything until ]]> is found.
+ . '](?!]>)' // One ] not followed by end of comment.
+ . '[^\]]*+' // Consume non-].
+ . ')*+' // Loop possessively.
+ . '(?:]]>)?'; // End of comment. If not found, match all input.
+
+ $regex =
+ '/(' // Capture the entire match.
+ . '<' // Find start of element.
+ . '(?(?=!--)' // Is this a comment?
+ . $comments // Find end of comment.
+ . '|'
+ . '(?(?=!\[CDATA\[)' // Is this a comment?
+ . $cdata // Find end of comment.
+ . '|'
+ . '[^>]*>?' // Find end of element. If not found, match all input.
+ . ')'
+ . ')'
+ . ')/s';
+ }
+
+ return preg_split( $regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Replace characters or phrases within HTML elements only.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.3
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -606,25 +656,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_replace_in_html_tags( $haystack, $replace_pairs ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Find all elements.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comments =
- '!' // Start of comment, after the <.
- . '(?:' // Unroll the loop: Consume everything until --> is found.
- . '-(?!->)' // Dash not followed by end of comment.
- . '[^\-]*+' // Consume non-dashes.
- . ')*+' // Loop possessively.
- . '(?:-->)?'; // End of comment. If not found, match all input.
-
- $regex =
- '/(' // Capture the entire match.
- . '<' // Find start of element.
- . '(?(?=!--)' // Is this a comment?
- . $comments // Find end of comment.
- . '|'
- . '[^>]*>?' // Find end of element. If not found, match all input.
- . ')'
- . ')/s';
-
- $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $textarr = wp_html_split( $haystack );
</ins><span class="cx" style="display: block; padding: 0 10px"> $changed = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Optimize when searching for one item.
</span></span></pre></div>
<a id="trunksrcwpincludesshortcodesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/shortcodes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/shortcodes.php 2015-07-28 22:06:52 UTC (rev 33468)
+++ trunk/src/wp-includes/shortcodes.php 2015-07-28 23:02:04 UTC (rev 33469)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -333,29 +333,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $trans = array( '[' => '[', ']' => ']' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $pattern = get_shortcode_regex();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $textarr = wp_html_split( $content );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment_regex =
- '!' // Start of comment, after the <.
- . '(?:' // Unroll the loop: Consume everything until --> is found.
- . '-(?!->)' // Dash not followed by end of comment.
- . '[^\-]*+' // Consume non-dashes.
- . ')*+' // Loop possessively.
- . '(?:-->)?'; // End of comment. If not found, match all input.
-
- $regex =
- '/(' // Capture the entire match.
- . '<' // Find start of element.
- . '(?(?=!--)' // Is this a comment?
- . $comment_regex // Find end of comment.
- . '|'
- . '[^>]*>?' // Find end of element. If not found, match all input.
- . ')'
- . ')/s';
-
- $textarr = preg_split( $regex, $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
-
</del><span class="cx" style="display: block; padding: 0 10px"> foreach ( $textarr as &$element ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( '<' !== $element[0] ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( '' == $element || '<' !== $element[0] ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -370,7 +351,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Encode all [ and ] chars.
</span><span class="cx" style="display: block; padding: 0 10px"> $element = strtr( $element, $trans );
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span></span></pre></div>
<a id="trunktestsphpunittestsformattingAutopphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/formatting/Autop.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/formatting/Autop.php 2015-07-28 22:06:52 UTC (rev 33468)
+++ trunk/tests/phpunit/tests/formatting/Autop.php 2015-07-28 23:02:04 UTC (rev 33469)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -399,4 +399,50 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $expected, trim( wpautop( $content ) ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * 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",
+ ),
+ );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media.php 2015-07-28 22:06:52 UTC (rev 33468)
+++ trunk/tests/phpunit/tests/media.php 2015-07-28 23:02:04 UTC (rev 33469)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -585,4 +585,115 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $post->post_excerpt );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @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 );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>