- Revision
- 250369
- Author
- [email protected]
- Date
- 2019-09-25 16:47:47 -0700 (Wed, 25 Sep 2019)
Log Message
[Cocoa] Regression(r212041) Safari adds a .dms extension automatically when downloading binaries with no extension
https://bugs.webkit.org/show_bug.cgi?id=202147
<rdar://problem/54886021>
Reviewed by Alexey Proskuryakov.
Source/WebCore:
When getting a suggested filename without extension (either from Content-Disposition header or from the download
attribute), we determine a suitable file extension based on the Content-Type header and append it. This is useful
since a lot of operating systems (such as macOS) rely on the file extension to determine file type.
The issue is that if the Content-Type is not provided or when it is provided but is "application/octet-stream",
we would append a .dms extension, which was unexpected. This patch makes it so that we no longer try to append
an extension when the resolved content type is "application/octet-stream".
Tests: http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html
http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html
http/tests/security/anchor-download-octet-stream-no-extension.html
* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::appendFileExtensionIfNecessary):
LayoutTests:
Add layout test coverage.
* http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream-expected.txt: Added.
* http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html: Added.
* http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain-expected.txt: Added.
* http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html: Added.
* http/tests/download/resources/content-disposition-pass-no-extension-octet-stream.php: Added.
* http/tests/download/resources/content-disposition-pass-no-extension-text-plain.php: Added.
* http/tests/security/anchor-download-octet-stream-no-extension-expected.txt: Added.
* http/tests/security/anchor-download-octet-stream-no-extension.html: Added.
* platform/mac-wk1/TestExpectations:
* platform/win/TestExpectations:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (250368 => 250369)
--- trunk/LayoutTests/ChangeLog 2019-09-25 23:08:27 UTC (rev 250368)
+++ trunk/LayoutTests/ChangeLog 2019-09-25 23:47:47 UTC (rev 250369)
@@ -1,3 +1,24 @@
+2019-09-25 Chris Dumez <[email protected]>
+
+ [Cocoa] Regression(r212041) Safari adds a .dms extension automatically when downloading binaries with no extension
+ https://bugs.webkit.org/show_bug.cgi?id=202147
+ <rdar://problem/54886021>
+
+ Reviewed by Alexey Proskuryakov.
+
+ Add layout test coverage.
+
+ * http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream-expected.txt: Added.
+ * http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html: Added.
+ * http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain-expected.txt: Added.
+ * http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html: Added.
+ * http/tests/download/resources/content-disposition-pass-no-extension-octet-stream.php: Added.
+ * http/tests/download/resources/content-disposition-pass-no-extension-text-plain.php: Added.
+ * http/tests/security/anchor-download-octet-stream-no-extension-expected.txt: Added.
+ * http/tests/security/anchor-download-octet-stream-no-extension.html: Added.
+ * platform/mac-wk1/TestExpectations:
+ * platform/win/TestExpectations:
+
2019-09-25 Megan Gardner <[email protected]>
Update selections after scrolling for iframes and hide selections while iframes and overflow scrolls are scrolling.
Added: trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream-expected.txt (0 => 250369)
--- trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream-expected.txt 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,8 @@
+Download started.
+Downloading URL with suggested filename "PASS"
+Download completed.
+Tests that the filename from the Content-Disposition header is used even if a download attribute is specified in HTML.
+
+The suggested filename above should be "PASS" (without extension) and the download should succeed.
+
+Link with download attribute.
Added: trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html (0 => 250369)
--- trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,36 @@
+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width">
+<script src=""
+<script>
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.setShouldLogDownloadCallbacks(true);
+ testRunner.waitUntilDownloadFinished();
+}
+</script>
+</head>
+<body>
+<p>Tests that the filename from the Content-Disposition header is used even if a download attribute is specified in HTML.</p>
+<p>The suggested filename above should be "PASS" (without extension) and the download should succeed.</p>
+<a id="download-url" href="" download="FAIL.txt">Link with download attribute.</a>
+<script>
+function click(elmt)
+{
+ if (!window.eventSender) {
+ alert('Click the link to run the test.');
+ return;
+ }
+ UIHelper.activateAt(elmt.offsetLeft + 5, elmt.offsetTop + 5);
+}
+
+function runTest()
+{
+ var link = document.getElementById("download-url");
+ click(link);
+}
+runTest();
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain-expected.txt (0 => 250369)
--- trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain-expected.txt 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,8 @@
+Download started.
+Downloading URL with suggested filename "PASS.txt"
+Download completed.
+Tests that the filename from the Content-Disposition header is used even if a download attribute is specified in HTML.
+
+The suggested filename above should be "PASS.txt" (with extension) and the download should succeed.
+
+Link with download attribute.
Added: trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html (0 => 250369)
--- trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,36 @@
+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width">
+<script src=""
+<script>
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.setShouldLogDownloadCallbacks(true);
+ testRunner.waitUntilDownloadFinished();
+}
+</script>
+</head>
+<body>
+<p>Tests that the filename from the Content-Disposition header is used even if a download attribute is specified in HTML.</p>
+<p>The suggested filename above should be "PASS.txt" (with extension) and the download should succeed.</p>
+<a id="download-url" href="" download="FAIL.txt">Link with download attribute.</a>
+<script>
+function click(elmt)
+{
+ if (!window.eventSender) {
+ alert('Click the link to run the test.');
+ return;
+ }
+ UIHelper.activateAt(elmt.offsetLeft + 5, elmt.offsetTop + 5);
+}
+
+function runTest()
+{
+ var link = document.getElementById("download-url");
+ click(link);
+}
+runTest();
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/download/resources/content-disposition-pass-no-extension-octet-stream.php (0 => 250369)
--- trunk/LayoutTests/http/tests/download/resources/content-disposition-pass-no-extension-octet-stream.php (rev 0)
+++ trunk/LayoutTests/http/tests/download/resources/content-disposition-pass-no-extension-octet-stream.php 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,6 @@
+<?php
+header("Content-Disposition: Attachment; filename=PASS");
+header("Content-Type: application/octet-stream");
+?>
+
+Test file content.
Added: trunk/LayoutTests/http/tests/download/resources/content-disposition-pass-no-extension-text-plain.php (0 => 250369)
--- trunk/LayoutTests/http/tests/download/resources/content-disposition-pass-no-extension-text-plain.php (rev 0)
+++ trunk/LayoutTests/http/tests/download/resources/content-disposition-pass-no-extension-text-plain.php 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,6 @@
+<?php
+header("Content-Disposition: Attachment; filename=PASS");
+header("Content-Type: text/plain");
+?>
+
+Test file content.
Added: trunk/LayoutTests/http/tests/security/anchor-download-octet-stream-no-extension-expected.txt (0 => 250369)
--- trunk/LayoutTests/http/tests/security/anchor-download-octet-stream-no-extension-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/security/anchor-download-octet-stream-no-extension-expected.txt 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,6 @@
+Download started.
+Downloading URL with suggested filename "foo"
+Download completed.
+Tests that a suggested filename on a download attribute is allowed if the link is a blob URL.
+
+The suggested filename at the top should be "foo" (without extension).
Added: trunk/LayoutTests/http/tests/security/anchor-download-octet-stream-no-extension.html (0 => 250369)
--- trunk/LayoutTests/http/tests/security/anchor-download-octet-stream-no-extension.html (rev 0)
+++ trunk/LayoutTests/http/tests/security/anchor-download-octet-stream-no-extension.html 2019-09-25 23:47:47 UTC (rev 250369)
@@ -0,0 +1,38 @@
+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width">
+<script src=""
+<script>
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.setShouldLogDownloadCallbacks(true);
+ testRunner.waitUntilDownloadFinished();
+ }
+</script>
+</head>
+<body>
+<p>
+Tests that a suggested filename on a download attribute is allowed if
+<a id="dl" download="foo">the link</a> is a blob URL.
+<p>The suggested filename at the top should be "foo" (without extension).</p>
+<script>
+ function click(elmt)
+ {
+ if (!window.eventSender)
+ return;
+
+ UIHelper.activateAt(elmt.offsetLeft + 5, elmt.offsetTop + 5);
+ }
+
+ function runTest()
+ {
+ var blob = new Blob(["Hello world!"], {type: "application/octet-stream"});
+ var link = document.getElementById("dl");
+ link.href = ""
+ click(link);
+ }
+ runTest();
+</script>
+</body>
+</html>
Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (250368 => 250369)
--- trunk/LayoutTests/platform/mac-wk1/TestExpectations 2019-09-25 23:08:27 UTC (rev 250368)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations 2019-09-25 23:47:47 UTC (rev 250369)
@@ -112,6 +112,9 @@
webkit.org/b/156069 http/tests/download/anchor-download-no-value.html [ Skip ]
webkit.org/b/156069 imported/w3c/web-platform-tests/html/semantics/text-level-semantics/the-a-element/a-download-click.html [ Skip ]
webkit.org/b/156069 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-area-element/area-download-click.html [ Skip ]
+webkit.org/b/156069 http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html [ Skip ]
+webkit.org/b/156069 http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html [ Skip ]
+webkit.org/b/156069 http/tests/security/anchor-download-octet-stream-no-extension.html [ Skip ]
# Not supported on WK1
media/no-fullscreen-when-hidden.html [ Skip ]
Modified: trunk/LayoutTests/platform/win/TestExpectations (250368 => 250369)
--- trunk/LayoutTests/platform/win/TestExpectations 2019-09-25 23:08:27 UTC (rev 250368)
+++ trunk/LayoutTests/platform/win/TestExpectations 2019-09-25 23:47:47 UTC (rev 250369)
@@ -476,6 +476,9 @@
http/tests/security/anchor-download-allow-data.html [ Skip ]
http/tests/security/anchor-download-allow-sameorigin.html [ Skip ]
http/tests/download/anchor-download-no-value.html [ Skip ]
+http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html [ Skip ]
+http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html [ Skip ]
+http/tests/security/anchor-download-octet-stream-no-extension.html [ Skip ]
# testRunner.setShouldDownloadUndisplayableMIMETypes() is not supported on WK1.
fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Skip ]
Modified: trunk/Source/WebCore/ChangeLog (250368 => 250369)
--- trunk/Source/WebCore/ChangeLog 2019-09-25 23:08:27 UTC (rev 250368)
+++ trunk/Source/WebCore/ChangeLog 2019-09-25 23:47:47 UTC (rev 250369)
@@ -1,3 +1,26 @@
+2019-09-25 Chris Dumez <[email protected]>
+
+ [Cocoa] Regression(r212041) Safari adds a .dms extension automatically when downloading binaries with no extension
+ https://bugs.webkit.org/show_bug.cgi?id=202147
+ <rdar://problem/54886021>
+
+ Reviewed by Alexey Proskuryakov.
+
+ When getting a suggested filename without extension (either from Content-Disposition header or from the download
+ attribute), we determine a suitable file extension based on the Content-Type header and append it. This is useful
+ since a lot of operating systems (such as macOS) rely on the file extension to determine file type.
+
+ The issue is that if the Content-Type is not provided or when it is provided but is "application/octet-stream",
+ we would append a .dms extension, which was unexpected. This patch makes it so that we no longer try to append
+ an extension when the resolved content type is "application/octet-stream".
+
+ Tests: http/tests/download/anchor-download-attribute-content-disposition-no-extension-octet-stream.html
+ http/tests/download/anchor-download-attribute-content-disposition-no-extension-text-plain.html
+ http/tests/security/anchor-download-octet-stream-no-extension.html
+
+ * platform/MIMETypeRegistry.cpp:
+ (WebCore::MIMETypeRegistry::appendFileExtensionIfNecessary):
+
2019-09-25 Megan Gardner <[email protected]>
Update selections after scrolling for iframes and hide selections while iframes and overflow scrolls are scrolling.
Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (250368 => 250369)
--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp 2019-09-25 23:08:27 UTC (rev 250368)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp 2019-09-25 23:47:47 UTC (rev 250369)
@@ -772,6 +772,9 @@
if (filename.isEmpty())
return emptyString();
+ if (equalIgnoringASCIICase(mimeType, defaultMIMEType()))
+ return filename;
+
if (filename.reverseFind('.') != notFound)
return filename;
@@ -779,7 +782,7 @@
if (preferredExtension.isEmpty())
return filename;
- return filename + "." + preferredExtension;
+ return makeString(filename, '.', preferredExtension);
}
} // namespace WebCore