Changeset 205306 in webkit
- Timestamp:
- Sep 1, 2016 12:27:57 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r205302 r205306 1 2016-09-01 Ricky Mondello <rmondello@apple.com> 2 3 YouTube Flash plug-in replacement facility should more gracefully handle malformed queries 4 https://bugs.webkit.org/show_bug.cgi?id=161476 5 <rdar://problem/28050847> 6 7 Reviewed by Eric Carlson. 8 9 Some YouTube Flash embeds use '&' instead of '?' to start the query portion of the URL. Before this patch, 10 our implementation discards all parts of the path after the '&', which could drop important query information 11 like the start time for the video. This patch treats anything after that '&' as a "malformed query" and uses 12 it as the query to restore to the transformed URL if there was no actual query in the original URL. 13 14 * Modules/plugins/YouTubePluginReplacement.cpp: 15 (WebCore::processAndCreateYouTubeURL): Add an out-parameter for the path after the first ampersand. 16 (WebCore::YouTubePluginReplacement::youTubeURLFromAbsoluteURL): If the input URL had no query, append 17 the possibly malformed one found after the first ampersand to the replacement URL. 18 1 19 2016-09-01 Alex Christensen <achristensen@webkit.org> 2 20 -
trunk/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp
r205271 r205306 201 201 } 202 202 203 static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL )203 static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL, String& outPathAfterFirstAmpersand) 204 204 { 205 205 if (!url.protocolIsInHTTPFamily()) … … 267 267 } 268 268 } else if (hasCaseInsensitivePrefix(path, "/v/") || hasCaseInsensitivePrefix(path, "/e/")) { 269 String videoID = url.lastPathComponent(); 270 271 // These URLs are funny - they don't have a ? for the first query parameter. 272 // Strip all characters after and including '&' to remove extraneous parameters after the video ID. 273 size_t ampersand = videoID.find('&'); 274 if (ampersand != notFound) 275 videoID = videoID.substring(0, ampersand); 276 277 if (!videoID.isEmpty()) 269 String lastPathComponent = url.lastPathComponent(); 270 String videoID; 271 String pathAfterFirstAmpersand; 272 273 size_t ampersandLocation = lastPathComponent.find('&'); 274 if (ampersandLocation != notFound) { 275 // Some URLs we care about use & in place of ? for the first query parameter. 276 videoID = lastPathComponent.substring(0, ampersandLocation); 277 pathAfterFirstAmpersand = lastPathComponent.substring(ampersandLocation + 1, lastPathComponent.length() - ampersandLocation); 278 } else 279 videoID = lastPathComponent; 280 281 if (!videoID.isEmpty()) { 282 outPathAfterFirstAmpersand = pathAfterFirstAmpersand; 278 283 return createYouTubeURL(videoID, emptyString()); 284 } 279 285 } 280 286 … … 291 297 { 292 298 bool isYouTubeShortenedURL = false; 293 URL youTubeURL = processAndCreateYouTubeURL(srcURL, isYouTubeShortenedURL); 299 String possibleMalformedQuery; 300 URL youTubeURL = processAndCreateYouTubeURL(srcURL, isYouTubeShortenedURL, possibleMalformedQuery); 294 301 if (srcURL.isEmpty() || youTubeURL.isEmpty()) 295 302 return srcString; … … 317 324 const String& srcURLPrefix = srcString.substring(0, locationOfPathBeforeVideoID); 318 325 String query = srcURL.query(); 326 // If the URL has no query, use the possibly malformed query we found. 327 if (query.isEmpty()) 328 query = possibleMalformedQuery; 319 329 320 330 // By default, the iframe will display information like the video title and uploader on top of the video. Don't display … … 325 335 query = "showinfo=0"; 326 336 327 // Append the query string if it is valid. Some sites apparently forget to add "?" for the query string, in that case, 328 // we will discard the parameters in the url. 329 // See: <rdar://problem/11535155> 337 // Append the query string if it is valid. 330 338 StringBuilder finalURL; 331 339 if (isYouTubeShortenedURL) -
trunk/Tools/ChangeLog
r205303 r205306 1 2016-09-01 Ricky Mondello <rmondello@apple.com> 2 3 YouTube Flash plug-in replacement facility should more gracefully handle malformed queries 4 https://bugs.webkit.org/show_bug.cgi?id=161476 5 <rdar://problem/28050847> 6 7 Reviewed by Eric Carlson. 8 9 * TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp: 10 (TestWebKitAPI::TEST_F): New tests. The first two and second-to-last test cases cover the "malformed" query 11 logic. A few other tests are added, too. 12 1 13 2016-09-01 Jer Noble <jer.noble@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp
r205212 r205306 62 62 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")); 63 63 64 // With an invalid query (see & instead of ?), we preserve and fix the query. 65 EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ&start=4", "http://www.youtube.com/embed/dQw4w9WgXcQ?start=4&showinfo=0")); 66 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")); 67 64 68 // Non-Flash URL is untouched. 65 69 EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ", "https://www.youtube.com/embed/dQw4w9WgXcQ")); 66 // Even with an extra parameter. 70 EXPECT_TRUE(test("http://www.youtube.com/embed/dQw4w9WgXcQ", "http://www.youtube.com/embed/dQw4w9WgXcQ")); 71 EXPECT_TRUE(test("https://youtube.com/embed/dQw4w9WgXcQ", "https://youtube.com/embed/dQw4w9WgXcQ")); 72 EXPECT_TRUE(test("http://youtube.com/embed/dQw4w9WgXcQ", "http://youtube.com/embed/dQw4w9WgXcQ")); 73 // Even with extra parameters. 74 EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ?start=4", "https://www.youtube.com/embed/dQw4w9WgXcQ?start=4")); 67 75 EXPECT_TRUE(test("http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1", "http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1")); 76 // Even with an invalid "query". 77 EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ&start=4", "https://www.youtube.com/embed/dQw4w9WgXcQ&start=4")); 78 79 // Don't transform anything with a non "/v/" path component immediately following the domain. 80 EXPECT_TRUE(test("https://www.youtube.com/something/v/dQw4w9WgXcQ", "https://www.youtube.com/something/v/dQw4w9WgXcQ")); 68 81 69 82 // Non-YouTube domain whose path looks like a Flash video shouldn't be transformed.
Note: See TracChangeset
for help on using the changeset viewer.