Changeset 247414 in webkit
- Timestamp:
- Jul 12, 2019 10:14:00 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r247411 r247414 1 2019-07-12 Andy Estes <aestes@apple.com> 2 3 [Cocoa] -loadFileURL:allowingReadAccessToURL: should fully resolve file URLs 4 https://bugs.webkit.org/show_bug.cgi?id=199768 5 <rdar://problem/52002206> 6 7 Reviewed by Geoffrey Garen. 8 9 -loadFileURL:allowingReadAccessToURL: used -_web_originalDataAsWTFString from WKNSURLExtras 10 to convert the file and read access NSURLs to strings, which under the hood calls 11 CFURLGetBytes(). CFURLGetBytes() gets the URL's string without considering the base URL, so 12 if the client creates a URL like this: 13 14 NSURL *url = [NSURL fileURLWithPath:@"tmpfile.txt" relativeToURL:[NSURL fileURLWithPath:@"/tmp"]] 15 16 ... then -_web_originalDataAsWTFString will merely return the string "tmpfile.txt". When 17 that is later converted back to a URL in WebPageProxy::loadFile(), we lose track of the base 18 component and refuse to load something that no longer looks like a file: URL. 19 20 Fixed this by fully resolving the URLs passed to -loadFileURL:allowingReadAccessToURL: when 21 converting to strings by using -[NSURL absoluteString] instead of -_web_originalDataAsWTFString. 22 23 * Shared/Cocoa/WKNSURLExtras.mm: 24 (-[NSURL _web_originalDataAsWTFString]): 25 * UIProcess/API/Cocoa/WKWebView.mm: 26 (-[WKWebView loadFileURL:allowingReadAccessToURL:]): 27 1 28 2019-07-12 Megan Gardner <megan_gardner@apple.com> 2 29 -
trunk/Source/WebKit/Shared/Cocoa/WKNSURLExtras.mm
r238771 r247414 48 48 - (String)_web_originalDataAsWTFString 49 49 { 50 // FIXME: Why is it OK to ignore base URL here? 50 51 CString originalData; 51 52 WTF::getURLBytes((__bridge CFURLRef)self, originalData); -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r247344 r247414 953 953 [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", readAccessURL]; 954 954 955 return wrapper(_page->loadFile( [URL _web_originalDataAsWTFString], [readAccessURL _web_originalDataAsWTFString]));955 return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString)); 956 956 } 957 957 -
trunk/Tools/ChangeLog
r247413 r247414 1 2019-07-12 Andy Estes <aestes@apple.com> 2 3 [Cocoa] -loadFileURL:allowingReadAccessToURL: should fully resolve file URLs 4 https://bugs.webkit.org/show_bug.cgi?id=199768 5 <rdar://problem/52002206> 6 7 Reviewed by Geoffrey Garen. 8 9 * TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm: 10 (TEST): 11 1 12 2019-07-12 Aakash Jain <aakash_jain@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm
r246694 r247414 67 67 EXPECT_WK_STREQ(webView.get()._resourceDirectoryURL.path, file.URLByDeletingLastPathComponent.path); 68 68 } 69 70 TEST(WKWebView, LoadRelativeFileURL) 71 { 72 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 73 74 auto delegate = adoptNS([[TestNavigationDelegate alloc] init]); 75 [webView setNavigationDelegate:delegate.get()]; 76 77 NSString *path = [NSBundle.mainBundle pathForResource:@"simple" ofType:@"html" inDirectory:@"TestWebKitAPI.resources"]; 78 NSURL *baseURL = [NSURL fileURLWithPath:path.stringByDeletingLastPathComponent]; 79 NSURL *fileURL = [NSURL fileURLWithPath:path.lastPathComponent relativeToURL:baseURL]; 80 EXPECT_NOT_NULL([webView loadFileURL:fileURL allowingReadAccessToURL:fileURL.URLByDeletingLastPathComponent]); 81 [delegate waitForDidFinishNavigation]; 82 EXPECT_WK_STREQ([webView _resourceDirectoryURL].path, fileURL.URLByDeletingLastPathComponent.path); 83 }
Note: See TracChangeset
for help on using the changeset viewer.