Title: [285861] trunk
Revision
285861
Author
[email protected]
Date
2021-11-16 07:24:18 -0800 (Tue, 16 Nov 2021)

Log Message

Empty <input type=file> is represented incorrectly in FormData
https://bugs.webkit.org/show_bug.cgi?id=185416

Patch by Andreu Botella <[email protected]> on 2021-11-16
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window-expected.txt:

Source/WebCore:

When a FormData object is constructed from a form, an empty <input type="file"> control will
be represented as an empty file with an empty filename. According to the HTML spec, this
file must have "application/octet-stream" as its content type. WebKit has the empty string
instead. This change brings WebKit into alignment with the standard and with Firefox and
Chrome in this area.

Tests: imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window.html

* html/FileInputType.cpp:
(WebCore::FileInputType::appendFormData const):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (285860 => 285861)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-11-16 15:07:51 UTC (rev 285860)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-11-16 15:24:18 UTC (rev 285861)
@@ -1,3 +1,12 @@
+2021-11-16  Andreu Botella  <[email protected]>
+
+        Empty <input type=file> is represented incorrectly in FormData
+        https://bugs.webkit.org/show_bug.cgi?id=185416
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window-expected.txt:
+
 2021-11-16  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r280078, r280290 and r282008.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window-expected.txt (285860 => 285861)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window-expected.txt	2021-11-16 15:07:51 UTC (rev 285860)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window-expected.txt	2021-11-16 15:24:18 UTC (rev 285861)
@@ -1,5 +1,5 @@
 
-FAIL Empty <input type=file> is still added to the form's entry list assert_equals: type expected "application/octet-stream" but got ""
+PASS Empty <input type=file> is still added to the form's entry list
 PASS Empty <input type=file> shows up in the urlencoded serialization
 PASS Empty <input type=file> shows up in the multipart/form-data serialization
 FAIL Empty <input type=file> shows up in the text/plain serialization assert_equals: expected "hi=\n" but got "hi="

Modified: trunk/Source/WebCore/ChangeLog (285860 => 285861)


--- trunk/Source/WebCore/ChangeLog	2021-11-16 15:07:51 UTC (rev 285860)
+++ trunk/Source/WebCore/ChangeLog	2021-11-16 15:24:18 UTC (rev 285861)
@@ -1,3 +1,21 @@
+2021-11-16  Andreu Botella  <[email protected]>
+
+        Empty <input type=file> is represented incorrectly in FormData
+        https://bugs.webkit.org/show_bug.cgi?id=185416
+
+        Reviewed by Chris Dumez.
+
+        When a FormData object is constructed from a form, an empty <input type="file"> control will
+        be represented as an empty file with an empty filename. According to the HTML spec, this
+        file must have "application/octet-stream" as its content type. WebKit has the empty string
+        instead. This change brings WebKit into alignment with the standard and with Firefox and
+        Chrome in this area.
+
+        Tests: imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window.html
+
+        * html/FileInputType.cpp:
+        (WebCore::FileInputType::appendFormData const):
+
 2021-11-16  Alan Bujtas  <[email protected]>
 
         [LFC][IFC] Fix fast/text/text-indent-inside-float.html

Modified: trunk/Source/WebCore/html/FileInputType.cpp (285860 => 285861)


--- trunk/Source/WebCore/html/FileInputType.cpp	2021-11-16 15:07:51 UTC (rev 285860)
+++ trunk/Source/WebCore/html/FileInputType.cpp	2021-11-16 15:24:18 UTC (rev 285861)
@@ -178,11 +178,16 @@
         return true;
     }
 
-    // If no filename at all is entered, return successful but empty.
-    // Null would be more logical, but Netscape posts an empty file. Argh.
+    // If no filename at all is entered, return successful but empty, with
+    // application/octet-stream content type. Null would be more logical, but
+    // Netscape posts an empty file. Argh.
     if (fileList->isEmpty()) {
         auto* document = element() ? &element()->document() : nullptr;
-        formData.append(name, File::create(document, emptyString()));
+        auto file = File::create(
+            document,
+            Blob::create(document, { }, "application/octet-stream"),
+            emptyString());
+        formData.append(name, file);
         return true;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to