Changeset 285861 in webkit


Ignore:
Timestamp:
Nov 16, 2021 7:24:18 AM (8 months ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Andreu Botella <andreu@andreubotella.com> 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):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r285857 r285861  
     12021-11-16  Andreu Botella  <andreu@andreubotella.com>
     2
     3        Empty <input type=file> is represented incorrectly in FormData
     4        https://bugs.webkit.org/show_bug.cgi?id=185416
     5
     6        Reviewed by Chris Dumez.
     7
     8        * web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window-expected.txt:
     9
    1102021-11-16  Commit Queue  <commit-queue@webkit.org>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window-expected.txt

    r285808 r285861  
    11
    2 FAIL Empty <input type=file> is still added to the form's entry list assert_equals: type expected "application/octet-stream" but got ""
     2PASS Empty <input type=file> is still added to the form's entry list
    33PASS Empty <input type=file> shows up in the urlencoded serialization
    44PASS Empty <input type=file> shows up in the multipart/form-data serialization
  • trunk/Source/WebCore/ChangeLog

    r285860 r285861  
     12021-11-16  Andreu Botella  <andreu@andreubotella.com>
     2
     3        Empty <input type=file> is represented incorrectly in FormData
     4        https://bugs.webkit.org/show_bug.cgi?id=185416
     5
     6        Reviewed by Chris Dumez.
     7
     8        When a FormData object is constructed from a form, an empty <input type="file"> control will
     9        be represented as an empty file with an empty filename. According to the HTML spec, this
     10        file must have "application/octet-stream" as its content type. WebKit has the empty string
     11        instead. This change brings WebKit into alignment with the standard and with Firefox and
     12        Chrome in this area.
     13
     14        Tests: imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-data-set-empty-file.window.html
     15
     16        * html/FileInputType.cpp:
     17        (WebCore::FileInputType::appendFormData const):
     18
    1192021-11-16  Alan Bujtas  <zalan@apple.com>
    220
  • trunk/Source/WebCore/html/FileInputType.cpp

    r285808 r285861  
    179179    }
    180180
    181     // If no filename at all is entered, return successful but empty.
    182     // Null would be more logical, but Netscape posts an empty file. Argh.
     181    // If no filename at all is entered, return successful but empty, with
     182    // application/octet-stream content type. Null would be more logical, but
     183    // Netscape posts an empty file. Argh.
    183184    if (fileList->isEmpty()) {
    184185        auto* document = element() ? &element()->document() : nullptr;
    185         formData.append(name, File::create(document, emptyString()));
     186        auto file = File::create(
     187            document,
     188            Blob::create(document, { }, "application/octet-stream"),
     189            emptyString());
     190        formData.append(name, file);
    186191        return true;
    187192    }
Note: See TracChangeset for help on using the changeset viewer.