Title: [264962] trunk
- Revision
- 264962
- Author
- wenson_hs...@apple.com
- Date
- 2020-07-27 17:52:16 -0700 (Mon, 27 Jul 2020)
Log Message
[iOS] Drag and drop does not preserve file names that contain periods
https://bugs.webkit.org/show_bug.cgi?id=214701
<rdar://problem/66014009>
Reviewed by Tim Horton.
Source/WebCore:
Cocoa documentation does not make it clear whether the `-suggestedName` property on `NSItemProvider` should or
should not include the file extension. To avoid adding a redundant file extension, logic in
`WebItemProviderPasteboard` attempts to deduce whether the suggested name already contains an extension, and
only appends a file extension (taken from name of the original file) if the suggested name does not have one.
Unfortunately, since this logic only checks whether or not there is a period in the filename, it will
incorrectly avoid adding a file extension when the suggested name contains a period. To fix this, instead of
checking for the presence of a period, check to see whether the file extension of the suggested name is the
same, and append the extension if it isn't.
Test: DragAndDropTests.SuggestedNameContainsDot
* platform/ios/WebItemProviderPasteboard.mm:
(linkTemporaryItemProviderFilesToDropStagingDirectory):
Tools:
Add an API test to exercise both scenarios where the suggested name does and does not contain the extension.
* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
Rebaseline an existing API test.
* TestWebKitAPI/Tests/WebKitCocoa/gif-and-file-input.html:
Adjust this test case to support handling multiple uploaded files.
* TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (264961 => 264962)
--- trunk/Source/WebCore/ChangeLog 2020-07-28 00:36:59 UTC (rev 264961)
+++ trunk/Source/WebCore/ChangeLog 2020-07-28 00:52:16 UTC (rev 264962)
@@ -1,3 +1,26 @@
+2020-07-27 Wenson Hsieh <wenson_hs...@apple.com>
+
+ [iOS] Drag and drop does not preserve file names that contain periods
+ https://bugs.webkit.org/show_bug.cgi?id=214701
+ <rdar://problem/66014009>
+
+ Reviewed by Tim Horton.
+
+ Cocoa documentation does not make it clear whether the `-suggestedName` property on `NSItemProvider` should or
+ should not include the file extension. To avoid adding a redundant file extension, logic in
+ `WebItemProviderPasteboard` attempts to deduce whether the suggested name already contains an extension, and
+ only appends a file extension (taken from name of the original file) if the suggested name does not have one.
+
+ Unfortunately, since this logic only checks whether or not there is a period in the filename, it will
+ incorrectly avoid adding a file extension when the suggested name contains a period. To fix this, instead of
+ checking for the presence of a period, check to see whether the file extension of the suggested name is the
+ same, and append the extension if it isn't.
+
+ Test: DragAndDropTests.SuggestedNameContainsDot
+
+ * platform/ios/WebItemProviderPasteboard.mm:
+ (linkTemporaryItemProviderFilesToDropStagingDirectory):
+
2020-07-27 Zalan Bujtas <za...@apple.com>
Extension is sized incorrectly, content is cut off.
Modified: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm (264961 => 264962)
--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm 2020-07-28 00:36:59 UTC (rev 264961)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm 2020-07-28 00:52:16 UTC (rev 264962)
@@ -708,7 +708,7 @@
if (!suggestedName)
suggestedName = url.lastPathComponent ?: (isFolder ? defaultDropFolderName : defaultDropFileName);
- if (![suggestedName containsString:@"."] && !isFolder)
+ if ([suggestedName.pathExtension caseInsensitiveCompare:url.pathExtension] != NSOrderedSame && !isFolder)
suggestedName = [suggestedName stringByAppendingPathExtension:url.pathExtension];
destination = [NSURL fileURLWithPath:[temporaryDropDataDirectory stringByAppendingPathComponent:suggestedName]];
Modified: trunk/Tools/ChangeLog (264961 => 264962)
--- trunk/Tools/ChangeLog 2020-07-28 00:36:59 UTC (rev 264961)
+++ trunk/Tools/ChangeLog 2020-07-28 00:52:16 UTC (rev 264962)
@@ -1,3 +1,24 @@
+2020-07-27 Wenson Hsieh <wenson_hs...@apple.com>
+
+ [iOS] Drag and drop does not preserve file names that contain periods
+ https://bugs.webkit.org/show_bug.cgi?id=214701
+ <rdar://problem/66014009>
+
+ Reviewed by Tim Horton.
+
+ Add an API test to exercise both scenarios where the suggested name does and does not contain the extension.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+
+ Rebaseline an existing API test.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/gif-and-file-input.html:
+
+ Adjust this test case to support handling multiple uploaded files.
+
+ * TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:
+ (TestWebKitAPI::TEST):
+
2020-07-27 Chris Dumez <cdu...@apple.com>
Update release*() functions on ExceptionOr() to always release the member
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (264961 => 264962)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm 2020-07-28 00:36:59 UTC (rev 264961)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm 2020-07-28 00:52:16 UTC (rev 264962)
@@ -2178,8 +2178,8 @@
_WKAttachment *attachment = [dragAndDropSimulator insertedAttachments].firstObject;
_WKAttachmentInfo *info = attachment.info;
EXPECT_WK_STREQ("image/png", info.contentType);
- EXPECT_WK_STREQ("image.hello", info.filePath.lastPathComponent);
- EXPECT_WK_STREQ("image.hello", info.name);
+ EXPECT_WK_STREQ("image.hello.png", info.filePath.lastPathComponent);
+ EXPECT_WK_STREQ("image.hello.png", info.name);
[webView expectElementCount:1 querySelector:@"IMG"];
});
}
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/gif-and-file-input.html (264961 => 264962)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/gif-and-file-input.html 2020-07-28 00:36:59 UTC (rev 264961)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/gif-and-file-input.html 2020-07-28 00:52:16 UTC (rev 264962)
@@ -16,13 +16,16 @@
<body>
<div><img src=""
- <div><input id="input" type="file"></input></div>
+ <div><input multiple id="input" type="file"></input></div>
<div id="output"></div>
</body>
<script>
input.addEventListener("change", () => {
- let file = input.files[0];
- output.textContent = `${file.name} (${file.type})`;
+ for (let file of input.files) {
+ let pre = document.createElement("pre");
+ pre.textContent = `${file.name} (${file.type})`;
+ output.appendChild(pre);
+ }
});
</script>
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm (264961 => 264962)
--- trunk/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm 2020-07-28 00:36:59 UTC (rev 264961)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm 2020-07-28 00:52:16 UTC (rev 264962)
@@ -2136,6 +2136,26 @@
EXPECT_FALSE(isCompletelyWhite([(UIImageView *)finalPreview.view image]));
}
+TEST(DragAndDropTests, SuggestedNameContainsDot)
+{
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"gif-and-file-input"];
+
+ auto firstItem = adoptNS([[NSItemProvider alloc] init]);
+ [firstItem registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG withData:testIconImageData()];
+ [firstItem setSuggestedName:@"one.foo"];
+
+ auto secondItem = adoptNS([[NSItemProvider alloc] init]);
+ [secondItem registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG withData:testIconImageData()];
+ [secondItem setSuggestedName:@"two.foo.PNG"];
+
+ auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]);
+ [simulator setExternalItemProviders:@[ firstItem.get(), secondItem.get() ]];
+ [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(100, 300)];
+
+ EXPECT_WK_STREQ("one.foo.png (image/png)\ntwo.foo.PNG (image/png)", [webView stringByEvaluatingJavaScript:@"output.innerText"]);
+}
+
} // namespace TestWebKitAPI
#endif // ENABLE(DRAG_SUPPORT) && PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes