Changeset 286427 in webkit
- Timestamp:
- Dec 2, 2021 7:34:01 AM (8 months ago)
- Location:
- trunk
- Files:
-
- 8 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt (modified) (2 diffs)
-
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/text-plain.window-expected.txt (modified) (6 diffs)
-
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/urlencoded2.window-expected.txt (modified) (6 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/FileInputType.cpp (modified) (2 diffs)
-
Source/WebCore/platform/network/FormData.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r286425 r286427 1 2021-12-02 Andreu Botella <andreu@andreubotella.com> 2 3 File inputs in non-multipart form submissions show up as string values in the formdata event 4 https://bugs.webkit.org/show_bug.cgi?id=233725 5 6 Reviewed by Chris Dumez. 7 8 Added tests in web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html 9 to check that file inputs show up as File entries in the formdata event. 10 11 * web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt: 12 * web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html: 13 * web-platform-tests/html/semantics/forms/form-submission-0/text-plain.window-expected.txt: 14 * web-platform-tests/html/semantics/forms/form-submission-0/urlencoded2.window-expected.txt: 15 1 16 2021-12-02 Alexey Shvayka <ashvayka@apple.com> 2 17 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt
r280310 r286427 1 2 3 1 4 2 5 … … 13 16 PASS "formdata" event bubbles, and is not cancelable. 14 17 PASS "formdata" event bubbles in an orphan tree. 18 PASS Files in a application/x-www-form-urlencoded form show up as File objects in the "formData" IDL attribute 19 PASS Files in a multipart/form-data form show up as File objects in the "formData" IDL attribute 20 PASS Files in a text/plain form show up as File objects in the "formData" IDL attribute 15 21 PASS "formData" IDL attribute should have entries for form-associated elements in the first event handler, and the second handler can read entries set by the first handler. 16 22 PASS Entries added to "formData" IDL attribute should be submitted. -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html
r279427 r286427 78 78 }, '"formdata" event bubbles in an orphan tree.'); 79 79 80 for (const enctype of ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]) { 81 test((t) => { 82 let form = populateForm('<input name=file type=file><input name=empty type=file>'); 83 form.enctype = enctype; 84 85 const file = new File([], "filename"); 86 const dataTransfer = new DataTransfer(); 87 dataTransfer.items.add(file); 88 form.querySelector('input[name=file]').files = dataTransfer.files; 89 90 form.addEventListener('formdata', t.step_func(e => { 91 assert_true(e.formData.has('file')); 92 assert_equals(e.formData.get('file'), file); 93 assert_true(e.formData.has('empty')); 94 assert_true(e.formData.get('empty') instanceof File); 95 })); 96 form.submit(); 97 }, `Files in a ${enctype} form show up as File objects in the "formData" IDL attribute`); 98 } 99 80 100 test(() => { 81 101 let listener1ok = false; -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/text-plain.window-expected.txt
r286221 r286427 3 3 PASS text/plain: Basic test (formdata event) 4 4 PASS text/plain: Basic File test (normal form) 5 FAIL text/plain: Basic File test (formdata event) assert_equals: expected "basic=file-test.txt\r\n" but got "" 5 PASS text/plain: Basic File test (formdata event) 6 6 PASS text/plain: 0x00 in name (normal form) 7 7 PASS text/plain: 0x00 in name (formdata event) … … 9 9 PASS text/plain: 0x00 in value (formdata event) 10 10 PASS text/plain: 0x00 in filename (normal form) 11 FAIL text/plain: 0x00 in filename (formdata event) assert_equals: expected "a=b\0c\r\n" but got "" 11 PASS text/plain: 0x00 in filename (formdata event) 12 12 PASS text/plain: \n in name (normal form) 13 13 PASS text/plain: \n in name (formdata event) … … 27 27 PASS text/plain: \n\r in value (formdata event) 28 28 PASS text/plain: \n in filename (normal form) 29 FAIL text/plain: \n in filename (formdata event) assert_equals: expected "a=b\r\nc\r\n" but got "" 29 PASS text/plain: \n in filename (formdata event) 30 30 PASS text/plain: \r in filename (normal form) 31 FAIL text/plain: \r in filename (formdata event) assert_equals: expected "a=b\r\nc\r\n" but got "" 31 PASS text/plain: \r in filename (formdata event) 32 32 PASS text/plain: \r\n in filename (normal form) 33 FAIL text/plain: \r\n in filename (formdata event) assert_equals: expected "a=b\r\nc\r\n" but got "" 33 PASS text/plain: \r\n in filename (formdata event) 34 34 PASS text/plain: \n\r in filename (normal form) 35 FAIL text/plain: \n\r in filename (formdata event) assert_equals: expected "a=b\r\n\r\nc\r\n" but got "" 35 PASS text/plain: \n\r in filename (formdata event) 36 36 PASS text/plain: double quote in name (normal form) 37 37 PASS text/plain: double quote in name (formdata event) … … 39 39 PASS text/plain: double quote in value (formdata event) 40 40 PASS text/plain: double quote in filename (normal form) 41 FAIL text/plain: double quote in filename (formdata event) assert_equals: expected "a=b\"c\r\n" but got "" 41 PASS text/plain: double quote in filename (formdata event) 42 42 PASS text/plain: single quote in name (normal form) 43 43 PASS text/plain: single quote in name (formdata event) … … 45 45 PASS text/plain: single quote in value (formdata event) 46 46 PASS text/plain: single quote in filename (normal form) 47 FAIL text/plain: single quote in filename (formdata event) assert_equals: expected "a=b'c\r\n" but got "" 47 PASS text/plain: single quote in filename (formdata event) 48 48 PASS text/plain: backslash in name (normal form) 49 49 PASS text/plain: backslash in name (formdata event) … … 51 51 PASS text/plain: backslash in value (formdata event) 52 52 PASS text/plain: backslash in filename (normal form) 53 FAIL text/plain: backslash in filename (formdata event) assert_equals: expected "a=b\\c\r\n" but got "" 53 PASS text/plain: backslash in filename (formdata event) 54 54 PASS text/plain: non-ASCII in name and value (normal form) 55 55 PASS text/plain: non-ASCII in name and value (formdata event) 56 56 PASS text/plain: non-ASCII in filename (normal form) 57 FAIL text/plain: non-ASCII in filename (formdata event) assert_equals: expected "a=É.txt\r\n" but got "" 57 PASS text/plain: non-ASCII in filename (formdata event) 58 58 PASS text/plain: characters not in encoding in name and value (normal form) 59 59 PASS text/plain: characters not in encoding in name and value (formdata event) 60 60 PASS text/plain: character not in encoding in filename (normal form) 61 FAIL text/plain: character not in encoding in filename (formdata event) assert_equals: expected "á=💩\r\n" but got "" 61 PASS text/plain: character not in encoding in filename (formdata event) 62 62 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/urlencoded2.window-expected.txt
r285810 r286427 3 3 PASS application/x-www-form-urlencoded: Basic test (formdata event) 4 4 PASS application/x-www-form-urlencoded: Basic File test (normal form) 5 FAIL application/x-www-form-urlencoded: Basic File test (formdata event) assert_equals: expected "basic=file-test.txt" but got "" 5 PASS application/x-www-form-urlencoded: Basic File test (formdata event) 6 6 PASS application/x-www-form-urlencoded: 0x00 in name (normal form) 7 7 PASS application/x-www-form-urlencoded: 0x00 in name (formdata event) … … 9 9 PASS application/x-www-form-urlencoded: 0x00 in value (formdata event) 10 10 PASS application/x-www-form-urlencoded: 0x00 in filename (normal form) 11 FAIL application/x-www-form-urlencoded: 0x00 in filename (formdata event) assert_equals: expected "a=b%00c" but got "" 11 PASS application/x-www-form-urlencoded: 0x00 in filename (formdata event) 12 12 PASS application/x-www-form-urlencoded: \n in name (normal form) 13 13 PASS application/x-www-form-urlencoded: \n in name (formdata event) … … 27 27 PASS application/x-www-form-urlencoded: \n\r in value (formdata event) 28 28 PASS application/x-www-form-urlencoded: \n in filename (normal form) 29 FAIL application/x-www-form-urlencoded: \n in filename (formdata event) assert_equals: expected "a=b%0D%0Ac" but got "" 29 PASS application/x-www-form-urlencoded: \n in filename (formdata event) 30 30 PASS application/x-www-form-urlencoded: \r in filename (normal form) 31 FAIL application/x-www-form-urlencoded: \r in filename (formdata event) assert_equals: expected "a=b%0D%0Ac" but got "" 31 PASS application/x-www-form-urlencoded: \r in filename (formdata event) 32 32 PASS application/x-www-form-urlencoded: \r\n in filename (normal form) 33 FAIL application/x-www-form-urlencoded: \r\n in filename (formdata event) assert_equals: expected "a=b%0D%0Ac" but got "" 33 PASS application/x-www-form-urlencoded: \r\n in filename (formdata event) 34 34 PASS application/x-www-form-urlencoded: \n\r in filename (normal form) 35 FAIL application/x-www-form-urlencoded: \n\r in filename (formdata event) assert_equals: expected "a=b%0D%0A%0D%0Ac" but got "" 35 PASS application/x-www-form-urlencoded: \n\r in filename (formdata event) 36 36 PASS application/x-www-form-urlencoded: double quote in name (normal form) 37 37 PASS application/x-www-form-urlencoded: double quote in name (formdata event) … … 39 39 PASS application/x-www-form-urlencoded: double quote in value (formdata event) 40 40 PASS application/x-www-form-urlencoded: double quote in filename (normal form) 41 FAIL application/x-www-form-urlencoded: double quote in filename (formdata event) assert_equals: expected "a=b%22c" but got "" 41 PASS application/x-www-form-urlencoded: double quote in filename (formdata event) 42 42 PASS application/x-www-form-urlencoded: single quote in name (normal form) 43 43 PASS application/x-www-form-urlencoded: single quote in name (formdata event) … … 45 45 PASS application/x-www-form-urlencoded: single quote in value (formdata event) 46 46 PASS application/x-www-form-urlencoded: single quote in filename (normal form) 47 FAIL application/x-www-form-urlencoded: single quote in filename (formdata event) assert_equals: expected "a=b%27c" but got "" 47 PASS application/x-www-form-urlencoded: single quote in filename (formdata event) 48 48 PASS application/x-www-form-urlencoded: backslash in name (normal form) 49 49 PASS application/x-www-form-urlencoded: backslash in name (formdata event) … … 51 51 PASS application/x-www-form-urlencoded: backslash in value (formdata event) 52 52 PASS application/x-www-form-urlencoded: backslash in filename (normal form) 53 FAIL application/x-www-form-urlencoded: backslash in filename (formdata event) assert_equals: expected "a=b%5Cc" but got "" 53 PASS application/x-www-form-urlencoded: backslash in filename (formdata event) 54 54 PASS application/x-www-form-urlencoded: non-ASCII in name and value (normal form) 55 55 PASS application/x-www-form-urlencoded: non-ASCII in name and value (formdata event) 56 56 PASS application/x-www-form-urlencoded: non-ASCII in filename (normal form) 57 FAIL application/x-www-form-urlencoded: non-ASCII in filename (formdata event) assert_equals: expected "a=%C9%99.txt" but got "" 57 PASS application/x-www-form-urlencoded: non-ASCII in filename (formdata event) 58 58 PASS application/x-www-form-urlencoded: characters not in encoding in name and value (normal form) 59 59 PASS application/x-www-form-urlencoded: characters not in encoding in name and value (formdata event) 60 60 PASS application/x-www-form-urlencoded: character not in encoding in filename (normal form) 61 FAIL application/x-www-form-urlencoded: character not in encoding in filename (formdata event) assert_equals: expected "%E1=%26%23128169%3B" but got "" 61 PASS application/x-www-form-urlencoded: character not in encoding in filename (formdata event) 62 62 -
trunk/Source/WebCore/ChangeLog
r286426 r286427 1 2021-12-02 Andreu Botella <andreu@andreubotella.com> 2 3 File inputs in non-multipart form submissions show up as string values in the formdata event 4 https://bugs.webkit.org/show_bug.cgi?id=233725 5 6 Reviewed by Chris Dumez. 7 8 When a form's entry list was constructed form a non-multipart/form-data form submission, 9 file inputs were added to the DOMFormData object as string values consisting of the file's 10 filename. Before r280310, this optimization was unobservable, since the DOMFormData object 11 was never exposed to the user halfway through a form submission. 12 13 r280310 changed this by adding the formdata event, which fires at the end of the "construct 14 the entry list" algorithm and can be used to both inspect and modify the DOMFormData object. 15 This means that it is now observable that file inputs in urlencoded and text/plain form 16 submissions are encoded as their filenames, and that any new File entries added to the 17 DOMFormData object the event listeners will be skipped when building the form payload. 18 19 This change fixes that by always adding file inputs to DOMFormData as File entries, and 20 using a File's filename as the string value in FormData::appendNonMultipartKeyValuePairItems 21 22 Tests: imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html 23 imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/text-plain.window.html 24 imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/urlencoded2.window.html 25 26 * html/FileInputType.cpp: 27 (WebCore::FileInputType::appendFormData const): Changed to always add File entries to the 28 DOMFormData object, rather than adding the filenames as string values when `multipart` is 29 false. 30 * platform/network/FormData.cpp: 31 (WebCore::FormData::appendNonMultiPartKeyValuePairItems): Changed to encode File entry 32 values as their filenames, rather than skipping them. 33 1 34 2021-12-02 Tyler Wilcock <tyler_w@apple.com> 2 35 -
trunk/Source/WebCore/html/FileInputType.cpp
r285932 r286427 159 159 } 160 160 161 bool FileInputType::appendFormData(DOMFormData& formData, bool multipart) const161 bool FileInputType::appendFormData(DOMFormData& formData, bool) const 162 162 { 163 163 ASSERT(element()); … … 166 166 167 167 auto name = element()->name(); 168 169 if (!multipart) {170 // Send only the basenames.171 // 4.10.16.4 and 4.10.16.6 sections in HTML5.172 173 if (fileList->isEmpty())174 formData.append(name, emptyString());175 176 for (auto& file : fileList->files())177 formData.append(name, file->name());178 return true;179 }180 168 181 169 // If no filename at all is entered, return successful but empty. -
trunk/Source/WebCore/platform/network/FormData.cpp
r284095 r286427 274 274 Vector<char> encodedData; 275 275 for (auto& item : formData.items()) { 276 // FIXME: The expected behavior is to convert files to string for enctype "text/plain". Conversion may be added at "void DOMFormData::set(const String& name, Blob& blob, const String& filename)" or here. 277 // FIXME: Remove the following if statement when fixed. 278 if (!std::holds_alternative<String>(item.data)) 279 continue; 280 281 ASSERT(std::holds_alternative<String>(item.data)); 276 String stringValue = WTF::switchOn(item.data, 277 [](const String& string) { 278 return string; 279 }, [](const RefPtr<File>& file) { 280 return file->name(); 281 } 282 ); 282 283 283 284 auto normalizedName = normalizeStringData(encoding, item.name); 284 auto normalizedStringData = normalizeStringData(encoding, st d::get<String>(item.data));285 auto normalizedStringData = normalizeStringData(encoding, stringValue); 285 286 FormDataBuilder::addKeyValuePairAsFormData(encodedData, normalizedName, normalizedStringData, encodingType); 286 287 }
Note: See TracChangeset
for help on using the changeset viewer.