FormData should allow setting filename to empty
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Mar 2013 22:52:59 +0000 (22:52 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Mar 2013 22:52:59 +0000 (22:52 +0000)
        https://bugs.webkit.org/show_bug.cgi?id=111687

        Reviewed by Brady Eidson.

        Tests: http/tests/local/formdata/send-form-data-with-empty-blob-filename.html
               http/tests/local/formdata/send-form-data-with-empty-file-filename.html

        * platform/network/FormData.cpp: (WebCore::FormData::appendKeyValuePairItems):
        Missing value is a null string. If the string is empty, we should treat is as
        authoritative.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename.html [new file with mode: 0644]
LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename.html [new file with mode: 0644]
LayoutTests/http/tests/misc/empty-file-formdata.html
LayoutTests/http/tests/xmlhttprequest/resources/multipart-post-echo-filenames.php [new file with mode: 0644]
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/network/FormData.cpp

index 82002b1..fadf57d 100644 (file)
@@ -1,3 +1,18 @@
+2013-03-07  Alexey Proskuryakov  <ap@apple.com>
+
+        FormData should allow setting filename to empty
+        https://bugs.webkit.org/show_bug.cgi?id=111687
+
+        Reviewed by Brady Eidson.
+
+        * http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt: Added.
+        * http/tests/local/formdata/send-form-data-with-empty-blob-filename.html: Added.
+        * http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt: Added.
+        * http/tests/local/formdata/send-form-data-with-empty-file-filename.html: Added.
+        * http/tests/xmlhttprequest/resources/multipart-post-echo-filenames.php: Added.
+
+        * platform/wk2/TestExpectations: Skip one of the tests, as it uses beginDragWithFiles.
+
 2013-03-07  Roger Fong  <roger_fong@apple.com>
 
         Unreviewed gardening AppleWin port.
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt
new file mode 100644 (file)
index 0000000..f44261e
--- /dev/null
@@ -0,0 +1,11 @@
+Test that filename passed to FormData.append() takes precedence over default Blob filename 'blob', even if empty.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Sending FormData containing one blob with custom empty filename:
+PASS filename is ''
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename.html b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename.html
new file mode 100644 (file)
index 0000000..a01b0e0
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Test that filename passed to FormData.append() takes precedence over default Blob filename 'blob', even if empty.");
+
+self.jsTestIsAsync = true;
+
+function runTest()
+{
+    debug("Sending FormData containing one blob with custom empty filename:");
+
+    var formData = new FormData;
+    formData.append("blob", new Blob([""]), "");
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/multipart-post-echo-filenames.php", true);
+    xhr.onload = function() {
+        filename = xhr.responseText;
+        shouldBe("filename", "''");
+        finishJSTest();
+    }
+    xhr.send(formData);
+}
+
+runTest();
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt
new file mode 100644 (file)
index 0000000..37ea9af
--- /dev/null
@@ -0,0 +1,11 @@
+Test that filename passed to FormData.append() takes precedence over filename in File, even if empty.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Sending FormData containing one file with custom empty filename:
+PASS filename is ''
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename.html b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename.html
new file mode 100644 (file)
index 0000000..2ba9486
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/send-form-data-common.js"></script>
+<script>
+description("Test that filename passed to FormData.append() takes precedence over filename in File, even if empty.");
+
+self.jsTestIsAsync = true;
+
+function runTest()
+{
+    debug("Sending FormData containing one file with custom empty filename:");
+    
+    var input = document.getElementsByTagName("input")[0];
+    if (window.eventSender) {
+        eventSender.beginDragWithFiles(['../resources/file-for-drag-to-send.txt']);
+        moveMouseToCenterOfElement(input);
+        eventSender.mouseUp();
+    }
+
+    var formData = new FormData;
+    formData.append("file", input.files[0], "");
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/multipart-post-echo-filenames.php", true);
+    xhr.onload = function() {
+        filename = xhr.responseText;
+        shouldBe("filename", "''");
+        formDataTestingCleanup();
+        finishJSTest();
+    }
+
+    xhr.send(formData);
+}
+
+if (window.eventSender) {
+    runTest();
+} else {
+    debug("To run this test manually, please drag a file onto file input above");
+    document.getElementsByTagName("input")[0].onchange = runTest;
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
+
index 7fa300a..dc017e5 100644 (file)
@@ -15,7 +15,7 @@ window.onload = test;
 </script>
 </head>
 <body>
-<form enctype="multipart/form-data" method="POST" action="resources/check-unnamed-file-included-in-formdata.php">
+<form enctype="multipart/form-data" method="POST" action="http://127.0.0.1:8000">
 <input name="data" type="file"></input>
 </form>
 </body>
diff --git a/LayoutTests/http/tests/xmlhttprequest/resources/multipart-post-echo-filenames.php b/LayoutTests/http/tests/xmlhttprequest/resources/multipart-post-echo-filenames.php
new file mode 100644 (file)
index 0000000..c79cce9
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+$first = True;
+foreach ($_FILES as $file) {
+    if (!$first)
+        echo ",";
+    echo $file['name'];
+    $first = False;
+}
+?>
index 5ea176f..b5f6864 100644 (file)
@@ -868,6 +868,7 @@ http/tests/local/formdata/send-form-data-constructed-from-form.html
 http/tests/local/formdata/send-form-data-with-filename.html
 http/tests/local/formdata/send-form-data-with-sliced-file.html
 http/tests/local/formdata/send-form-data.html
+http/tests/local/formdata/send-form-data-with-empty-file-filename.html
 http/tests/local/formdata/upload-events.html
 http/tests/security/clipboard/clipboard-file-access.html
 media/video-src-blob.html
index 48bc467..e73ca5b 100644 (file)
@@ -1,3 +1,17 @@
+2013-03-07  Alexey Proskuryakov  <ap@apple.com>
+
+        FormData should allow setting filename to empty
+        https://bugs.webkit.org/show_bug.cgi?id=111687
+
+        Reviewed by Brady Eidson.
+
+        Tests: http/tests/local/formdata/send-form-data-with-empty-blob-filename.html
+               http/tests/local/formdata/send-form-data-with-empty-file-filename.html
+
+        * platform/network/FormData.cpp: (WebCore::FormData::appendKeyValuePairItems):
+        Missing value is a null string. If the string is empty, we should treat is as
+        authoritative.
+
 2013-03-07  David Hyatt  <hyatt@apple.com>
 
         REGRESSION: fast/border/border-fit-2.html needs updating
index 381d17b..f6d4588 100644 (file)
@@ -244,11 +244,11 @@ void FormData::appendKeyValuePairItems(const FormDataList& list, const TextEncod
                     }
 
                     // If a filename is passed in FormData.append(), use it instead of the file blob's name.
-                    if (!value.filename().isEmpty())
+                    if (!value.filename().isNull())
                         name = value.filename();
                 } else {
                     // For non-file blob, use the filename if it is passed in FormData.append().
-                    if (!value.filename().isEmpty())
+                    if (!value.filename().isNull())
                         name = value.filename();
                     else
                         name = "blob";