<!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>[33522] branches/4.0: Backport r33469 and r33470 to 4.0.</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/33522">33522</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/33522","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-07-31 01:43:11 +0000 (Fri, 31 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'>Backport <a href="https://core.trac.wordpress.org/changeset/33469">r33469</a> and <a href="https://core.trac.wordpress.org/changeset/33470">r33470</a> to 4.0.
See <a href="https://core.trac.wordpress.org/ticket/33106">#33106</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches40srcwpincludesclasswpembedphp">branches/4.0/src/wp-includes/class-wp-embed.php</a></li>
<li><a href="#branches40srcwpincludesformattingphp">branches/4.0/src/wp-includes/formatting.php</a></li>
<li><a href="#branches40srcwpincludesshortcodesphp">branches/4.0/src/wp-includes/shortcodes.php</a></li>
<li><a href="#branches40testsphpunittestsformattingAutopphp">branches/4.0/tests/phpunit/tests/formatting/Autop.php</a></li>
<li><a href="#branches40testsphpunittestsmediaphp">branches/4.0/tests/phpunit/tests/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches40srcwpincludesclasswpembedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/src/wp-includes/class-wp-embed.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/src/wp-includes/class-wp-embed.php   2015-07-31 01:42:39 UTC (rev 33521)
+++ branches/4.0/src/wp-includes/class-wp-embed.php     2015-07-31 01:43:11 UTC (rev 33522)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -326,11 +326,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="branches40srcwpincludesformattingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/src/wp-includes/formatting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/src/wp-includes/formatting.php       2015-07-31 01:42:39 UTC (rev 33521)
+++ branches/4.0/src/wp-includes/formatting.php 2015-07-31 01:43:11 UTC (rev 33522)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -405,8 +405,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
</span><span class="cx" style="display: block; padding: 0 10px">        $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
</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">        if ( strpos( $pee, '<option' ) !== false ) {
</span><span class="cx" style="display: block; padding: 0 10px">                // no P/BR around option
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -459,10 +459,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">@@ -473,25 +523,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="branches40srcwpincludesshortcodesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/src/wp-includes/shortcodes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/src/wp-includes/shortcodes.php       2015-07-31 01:42:39 UTC (rev 33521)
+++ branches/4.0/src/wp-includes/shortcodes.php 2015-07-31 01:43:11 UTC (rev 33522)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -332,29 +332,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $trans = array( '[' => '&#91;', ']' => '&#93;' );
</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">@@ -369,7 +350,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="branches40testsphpunittestsformattingAutopphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/tests/phpunit/tests/formatting/Autop.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/tests/phpunit/tests/formatting/Autop.php     2015-07-31 01:42:39 UTC (rev 33521)
+++ branches/4.0/tests/phpunit/tests/formatting/Autop.php       2015-07-31 01:43:11 UTC (rev 33522)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -400,4 +400,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="branches40testsphpunittestsmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/tests/phpunit/tests/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/tests/phpunit/tests/media.php        2015-07-31 01:42:39 UTC (rev 33521)
+++ branches/4.0/tests/phpunit/tests/media.php  2015-07-31 01:43:11 UTC (rev 33522)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -438,4 +438,117 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertTrue( has_image_size( 'test-size' ) );
</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.</p>
+<p>https://youtube.com/watch?v=TEST01YRHA0</p>
+<p><script><!--
+my_function();
+// --> </script></p>
+<p>https://youtube.com/watch?v=TEST02YRHA0</p>
+<p><a href="http://www.example.com/embed/TEST03YRHA0">http://www.example.com/embed/TEST03YRHA0</a></p>
+<p>http://www.example.com/embed/TEST04YRHA0</p>
+<p>Stop.</p>
+
+EOF;
+
+               $result = apply_filters( 'the_content', $content );
+               $this->assertEquals( $expected, $result );
+       }
+
+       /**
+        * @ticket 33016
+        */
+       function filter_wp_embed_shortcode_custom( $content, $url ) {
+               if ( 'https://www.example.com/?video=1' == $url ) {
+                       $content = '@embed URL was replaced@';
+               }
+               return $content;
+       }
+
+       /**
+        * @ticket 33016
+        */
+       function test_oembed_explicit_media_link() {
+               global $wp_embed;
+               add_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 2 );
+
+               $content = <<<EOF
+https://www.example.com/?video=1
+EOF;
+
+               $expected = <<<EOF
+
+@embed URL was replaced@
+
+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
+do not break this';
+// ]]>
+</script>
+EOF;
+
+               $result = $wp_embed->autoembed( $content );
+               $this->assertEquals( $content, $result );
+
+               remove_filter( 'embed_maybe_make_link', 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>