REGRESSION(r221839): Fix requests with FormData containing empty files
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2018 18:15:48 +0000 (18:15 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2018 18:15:48 +0000 (18:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184490
<rdar://problem/39385169>

Patch by Tadeu Zagallo <tzagallo@apple.com> on 2018-04-24
Reviewed by Geoffrey Garen.

Source/WebCore:

We should not append the blob to the FormData when it is a file but has no path. It broke
the submission since the request was failing to read the file in FormDataStreamCFNet.h:156

Test: http/tests/local/formdata/send-form-data-with-empty-file.html

* platform/network/FormData.cpp:
(WebCore::FormData::appendMultiPartFileValue):

LayoutTests:

Verify that the final boundary is present in the request body when submitting FormData containing an empty file.

* http/tests/local/formdata/send-form-data-with-empty-file-expected.txt: Added.
* http/tests/local/formdata/send-form-data-with-empty-file.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230963 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/network/FormData.cpp

index 8108261..49f880c 100644 (file)
@@ -1,3 +1,16 @@
+2018-04-24  Tadeu Zagallo  <tzagallo@apple.com>
+
+        REGRESSION(r221839): Fix requests with FormData containing empty files
+        https://bugs.webkit.org/show_bug.cgi?id=184490
+        <rdar://problem/39385169>
+
+        Reviewed by Geoffrey Garen.
+
+        Verify that the final boundary is present in the request body when submitting FormData containing an empty file.
+
+        * http/tests/local/formdata/send-form-data-with-empty-file-expected.txt: Added.
+        * http/tests/local/formdata/send-form-data-with-empty-file.html: Added.
+
 2018-04-23  Daniel Bates  <dabates@apple.com>
 
         Implement Same-Site cookies
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-expected.txt b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-expected.txt
new file mode 100644 (file)
index 0000000..972da12
--- /dev/null
@@ -0,0 +1,10 @@
+Test that we correctly send forms with empty files
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS lines[0] + "--" is lines[lines.length - 1]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file.html b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file.html
new file mode 100644 (file)
index 0000000..707083f
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<form action="http://127.0.0.1:8000/xmlhttprequest/resources/post-echo.cgi" method="post" enctype="multipart/form-data">
+  <input name="file" type="file">
+</form>
+<script src="../../../../resources/js-test-pre.js"></script>
+<script>
+
+description("Test that we correctly send forms with empty files");
+
+window.jsTestIsAsync = true;
+
+const form = document.forms[0];
+const request = new XMLHttpRequest();
+request.open("POST", form.action);
+request.onload = function() {
+    lines = request.responseText.trim().split('\r\n');
+    shouldBe('lines[0] + "--"', 'lines[lines.length - 1]');
+    finishJSTest();
+}
+request.send(new FormData(form));
+</script>
+<script src="../../../../resources/js-test-post.js"></script>
+</body>
+</html>
+
index c248971..8a14656 100644 (file)
@@ -1,3 +1,19 @@
+2018-04-24  Tadeu Zagallo  <tzagallo@apple.com>
+
+        REGRESSION(r221839): Fix requests with FormData containing empty files
+        https://bugs.webkit.org/show_bug.cgi?id=184490
+        <rdar://problem/39385169>
+
+        Reviewed by Geoffrey Garen.
+
+        We should not append the blob to the FormData when it is a file but has no path. It broke
+        the submission since the request was failing to read the file in FormDataStreamCFNet.h:156
+
+        Test: http/tests/local/formdata/send-form-data-with-empty-file.html
+
+        * platform/network/FormData.cpp:
+        (WebCore::FormData::appendMultiPartFileValue):
+
 2018-04-24  Zalan Bujtas  <zalan@apple.com>
 
         Fix project file after r230931.
index 65accc4..174b8b7 100644 (file)
@@ -223,7 +223,7 @@ void FormData::appendMultiPartFileValue(const File& file, Vector<char>& header,
 
     if (!file.path().isEmpty())
         appendFile(file.path(), shouldGenerateFile);
-    else
+    else if (file.size())
         appendBlob(file.url());
 }