Title: [207597] branches/safari-602-branch

Diff

Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (207596 => 207597)


--- 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)
@@ -1,5 +1,27 @@
 2016-10-20  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r205306. rdar://problem/28476952
+
+    2016-09-01  Ricky Mondello  <rmonde...@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_han...@apple.com>
+
         Merge r205274. rdar://problem/28476952
 
     2016-08-31  Ricky Mondello  <rmonde...@apple.com>

Modified: branches/safari-602-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp (207596 => 207597)


--- 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)
@@ -200,7 +200,7 @@
     return value->value;
 }
 
-static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL)
+static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL, String& outPathAfterFirstAmpersand)
 {
     if (!url.protocolIsInHTTPFamily())
         return URL();
@@ -266,16 +266,22 @@
             }
         }
     } else if (hasCaseInsensitivePrefix(path, "/v/") || hasCaseInsensitivePrefix(path, "/e/")) {
-        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())
+        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;
             return createYouTubeURL(videoID, emptyString());
+        }
     }
     
     return URL();
@@ -290,7 +296,8 @@
 String YouTubePluginReplacement::youTubeURLFromAbsoluteURL(const URL& srcURL, const String& srcString)
 {
     bool isYouTubeShortenedURL = false;
-    URL youTubeURL = processAndCreateYouTubeURL(srcURL, isYouTubeShortenedURL);
+    String possibleMalformedQuery;
+    URL youTubeURL = processAndCreateYouTubeURL(srcURL, isYouTubeShortenedURL, possibleMalformedQuery);
     if (srcURL.isEmpty() || youTubeURL.isEmpty())
         return srcString;
 
@@ -316,6 +323,9 @@
 
     const String& srcURLPrefix = srcString.substring(0, locationOfPathBeforeVideoID);
     String query = srcURL.query();
+    // If the URL has no query, use the possibly malformed query we found.
+    if (query.isEmpty())
+        query = possibleMalformedQuery;
 
     // By default, the iframe will display information like the video title and uploader on top of the video. Don't display
     // them if the embeding html doesn't specify it.
@@ -324,9 +334,7 @@
     else
         query = "showinfo=0";
     
-    // 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>
+    // Append the query string if it is valid.
     StringBuilder finalURL;
     if (isYouTubeShortenedURL)
         finalURL.appendLiteral("http://www.youtube.com");

Modified: branches/safari-602-branch/Tools/ChangeLog (207596 => 207597)


--- 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)
@@ -1,5 +1,21 @@
 2016-10-20  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r205306. rdar://problem/28476952
+
+    2016-09-01  Ricky Mondello  <rmonde...@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_han...@apple.com>
+
         Merge r205212. rdar://problem/28476952
 
     2016-08-30  Ricky Mondello  <rmonde...@apple.com>

Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp (207596 => 207597)


--- 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)
@@ -61,11 +61,24 @@
     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"));
 
+    // 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"));
+
     // Non-Flash URL is untouched.
     EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ", "https://www.youtube.com/embed/dQw4w9WgXcQ"));
-    // Even with an extra parameter.
+    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"));
     EXPECT_TRUE(test("http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1", "http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1"));
+    // Even with an invalid "query".
+    EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ&start=4", "https://www.youtube.com/embed/dQw4w9WgXcQ&start=4"));
 
+    // 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"));
+
     // Non-YouTube domain whose path looks like a Flash video shouldn't be transformed.
     EXPECT_TRUE(test("https://www.notyoutube.com/v/dQw4w9WgXcQ", "https://www.notyoutube.com/v/dQw4w9WgXcQ"));
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to