<!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>[207597] branches/safari-602-branch</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">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/207597">207597</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2016-10-20 02:59:22 -0700 (Thu, 20 Oct 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/205306">r205306</a>. rdar://problem/28476952</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceWebCoreChangeLog">branches/safari-602-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWebCoreModulespluginsYouTubePluginReplacementcpp">branches/safari-602-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp</a></li>
<li><a href="#branchessafari602branchToolsChangeLog">branches/safari-602-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari602branchToolsTestWebKitAPITestsWebCoreYouTubePluginReplacementcpp">branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari602branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (207596 => 207597)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/ChangeLog        2016-10-20 09:59:19 UTC (rev 207596)
+++ branches/safari-602-branch/Source/WebCore/ChangeLog        2016-10-20 09:59:22 UTC (rev 207597)
</span><span class="lines">@@ -1,5 +1,27 @@
</span><span class="cx"> 2016-10-20 Matthew Hanson <matthew_hanson@apple.com>
</span><span class="cx">
</span><ins>+ Merge r205306. rdar://problem/28476952
+
+ 2016-09-01 Ricky Mondello <rmondello@apple.com>
+
+ YouTube Flash plug-in replacement facility should more gracefully handle malformed queries
+ https://bugs.webkit.org/show_bug.cgi?id=161476
+ <rdar://problem/28050847>
+
+ Reviewed by Eric Carlson.
+
+ Some YouTube Flash embeds use '&' instead of '?' to start the query portion of the URL. Before this patch,
+ our implementation discards all parts of the path after the '&', which could drop important query information
+ like the start time for the video. This patch treats anything after that '&' as a "malformed query" and uses
+ it as the query to restore to the transformed URL if there was no actual query in the original URL.
+
+ * Modules/plugins/YouTubePluginReplacement.cpp:
+ (WebCore::processAndCreateYouTubeURL): Add an out-parameter for the path after the first ampersand.
+ (WebCore::YouTubePluginReplacement::youTubeURLFromAbsoluteURL): If the input URL had no query, append
+ the possibly malformed one found after the first ampersand to the replacement URL.
+
+2016-10-20 Matthew Hanson <matthew_hanson@apple.com>
+
</ins><span class="cx"> Merge r205274. rdar://problem/28476952
</span><span class="cx">
</span><span class="cx"> 2016-08-31 Ricky Mondello <rmondello@apple.com>
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreModulespluginsYouTubePluginReplacementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp (207596 => 207597)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp        2016-10-20 09:59:19 UTC (rev 207596)
+++ branches/safari-602-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp        2016-10-20 09:59:22 UTC (rev 207597)
</span><span class="lines">@@ -200,7 +200,7 @@
</span><span class="cx"> return value->value;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL)
</del><ins>+static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL, String& outPathAfterFirstAmpersand)
</ins><span class="cx"> {
</span><span class="cx"> if (!url.protocolIsInHTTPFamily())
</span><span class="cx"> return URL();
</span><span class="lines">@@ -266,16 +266,22 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> } else if (hasCaseInsensitivePrefix(path, "/v/") || hasCaseInsensitivePrefix(path, "/e/")) {
</span><del>- String videoID = url.lastPathComponent();
-
- // These URLs are funny - they don't have a ? for the first query parameter.
- // Strip all characters after and including '&' to remove extraneous parameters after the video ID.
- size_t ampersand = videoID.find('&');
- if (ampersand != notFound)
- videoID = videoID.substring(0, ampersand);
-
- if (!videoID.isEmpty())
</del><ins>+ String lastPathComponent = url.lastPathComponent();
+ String videoID;
+ String pathAfterFirstAmpersand;
+
+ size_t ampersandLocation = lastPathComponent.find('&');
+ if (ampersandLocation != notFound) {
+ // Some URLs we care about use & in place of ? for the first query parameter.
+ videoID = lastPathComponent.substring(0, ampersandLocation);
+ pathAfterFirstAmpersand = lastPathComponent.substring(ampersandLocation + 1, lastPathComponent.length() - ampersandLocation);
+ } else
+ videoID = lastPathComponent;
+
+ if (!videoID.isEmpty()) {
+ outPathAfterFirstAmpersand = pathAfterFirstAmpersand;
</ins><span class="cx"> return createYouTubeURL(videoID, emptyString());
</span><ins>+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return URL();
</span><span class="lines">@@ -290,7 +296,8 @@
</span><span class="cx"> String YouTubePluginReplacement::youTubeURLFromAbsoluteURL(const URL& srcURL, const String& srcString)
</span><span class="cx"> {
</span><span class="cx"> bool isYouTubeShortenedURL = false;
</span><del>- URL youTubeURL = processAndCreateYouTubeURL(srcURL, isYouTubeShortenedURL);
</del><ins>+ String possibleMalformedQuery;
+ URL youTubeURL = processAndCreateYouTubeURL(srcURL, isYouTubeShortenedURL, possibleMalformedQuery);
</ins><span class="cx"> if (srcURL.isEmpty() || youTubeURL.isEmpty())
</span><span class="cx"> return srcString;
</span><span class="cx">
</span><span class="lines">@@ -316,6 +323,9 @@
</span><span class="cx">
</span><span class="cx"> const String& srcURLPrefix = srcString.substring(0, locationOfPathBeforeVideoID);
</span><span class="cx"> String query = srcURL.query();
</span><ins>+ // If the URL has no query, use the possibly malformed query we found.
+ if (query.isEmpty())
+ query = possibleMalformedQuery;
</ins><span class="cx">
</span><span class="cx"> // By default, the iframe will display information like the video title and uploader on top of the video. Don't display
</span><span class="cx"> // them if the embeding html doesn't specify it.
</span><span class="lines">@@ -324,9 +334,7 @@
</span><span class="cx"> else
</span><span class="cx"> query = "showinfo=0";
</span><span class="cx">
</span><del>- // Append the query string if it is valid. Some sites apparently forget to add "?" for the query string, in that case,
- // we will discard the parameters in the url.
- // See: <rdar://problem/11535155>
</del><ins>+ // Append the query string if it is valid.
</ins><span class="cx"> StringBuilder finalURL;
</span><span class="cx"> if (isYouTubeShortenedURL)
</span><span class="cx"> finalURL.appendLiteral("http://www.youtube.com");
</span></span></pre></div>
<a id="branchessafari602branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Tools/ChangeLog (207596 => 207597)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/ChangeLog        2016-10-20 09:59:19 UTC (rev 207596)
+++ branches/safari-602-branch/Tools/ChangeLog        2016-10-20 09:59:22 UTC (rev 207597)
</span><span class="lines">@@ -1,5 +1,21 @@
</span><span class="cx"> 2016-10-20 Matthew Hanson <matthew_hanson@apple.com>
</span><span class="cx">
</span><ins>+ Merge r205306. rdar://problem/28476952
+
+ 2016-09-01 Ricky Mondello <rmondello@apple.com>
+
+ YouTube Flash plug-in replacement facility should more gracefully handle malformed queries
+ https://bugs.webkit.org/show_bug.cgi?id=161476
+ <rdar://problem/28050847>
+
+ Reviewed by Eric Carlson.
+
+ * TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp:
+ (TestWebKitAPI::TEST_F): New tests. The first two and second-to-last test cases cover the "malformed" query
+ logic. A few other tests are added, too.
+
+2016-10-20 Matthew Hanson <matthew_hanson@apple.com>
+
</ins><span class="cx"> Merge r205212. rdar://problem/28476952
</span><span class="cx">
</span><span class="cx"> 2016-08-30 Ricky Mondello <rmondello@apple.com>
</span></span></pre></div>
<a id="branchessafari602branchToolsTestWebKitAPITestsWebCoreYouTubePluginReplacementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp (207596 => 207597)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp        2016-10-20 09:59:19 UTC (rev 207596)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp        2016-10-20 09:59:22 UTC (rev 207597)
</span><span class="lines">@@ -61,11 +61,24 @@
</span><span class="cx"> EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ?start=4", "http://www.youtube.com/embed/dQw4w9WgXcQ?start=4&showinfo=0"));
</span><span class="cx"> EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ?start=4&fs=1", "http://www.youtube.com/embed/dQw4w9WgXcQ?start=4&fs=1&showinfo=0"));
</span><span class="cx">
</span><ins>+ // With an invalid query (see & instead of ?), we preserve and fix the query.
+ EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ&start=4", "http://www.youtube.com/embed/dQw4w9WgXcQ?start=4&showinfo=0"));
+ EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ&start=4&fs=1", "http://www.youtube.com/embed/dQw4w9WgXcQ?start=4&fs=1&showinfo=0"));
+
</ins><span class="cx"> // Non-Flash URL is untouched.
</span><span class="cx"> EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ", "https://www.youtube.com/embed/dQw4w9WgXcQ"));
</span><del>- // Even with an extra parameter.
</del><ins>+ EXPECT_TRUE(test("http://www.youtube.com/embed/dQw4w9WgXcQ", "http://www.youtube.com/embed/dQw4w9WgXcQ"));
+ EXPECT_TRUE(test("https://youtube.com/embed/dQw4w9WgXcQ", "https://youtube.com/embed/dQw4w9WgXcQ"));
+ EXPECT_TRUE(test("http://youtube.com/embed/dQw4w9WgXcQ", "http://youtube.com/embed/dQw4w9WgXcQ"));
+ // Even with extra parameters.
+ EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ?start=4", "https://www.youtube.com/embed/dQw4w9WgXcQ?start=4"));
</ins><span class="cx"> EXPECT_TRUE(test("http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1", "http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1"));
</span><ins>+ // Even with an invalid "query".
+ EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ&start=4", "https://www.youtube.com/embed/dQw4w9WgXcQ&start=4"));
</ins><span class="cx">
</span><ins>+ // Don't transform anything with a non "/v/" path component immediately following the domain.
+ EXPECT_TRUE(test("https://www.youtube.com/something/v/dQw4w9WgXcQ", "https://www.youtube.com/something/v/dQw4w9WgXcQ"));
+
</ins><span class="cx"> // Non-YouTube domain whose path looks like a Flash video shouldn't be transformed.
</span><span class="cx"> EXPECT_TRUE(test("https://www.notyoutube.com/v/dQw4w9WgXcQ", "https://www.notyoutube.com/v/dQw4w9WgXcQ"));
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>