Title: [145097] trunk
Revision
145097
Author
a...@apple.com
Date
2013-03-07 10:25:10 -0800 (Thu, 07 Mar 2013)

Log Message

        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

        * html/FileInputType.cpp: (WebCore::FileInputType::appendFormData):
        Use a Blob for empty file input, not a hacky File with empty path.

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

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (145096 => 145097)


--- trunk/LayoutTests/ChangeLog	2013-03-07 18:23:47 UTC (rev 145096)
+++ trunk/LayoutTests/ChangeLog	2013-03-07 18:25:10 UTC (rev 145097)
@@ -1,3 +1,18 @@
+2013-03-07  Alexey Proskuryakov  <a...@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  Dean Jackson  <d...@apple.com>
 
         inspector/debugger/debugger-expand-scope.html sometimes fails on Apple MountainLion Release WK1 (Tests)

Added: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt (0 => 145097)


--- trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt	2013-03-07 18:25:10 UTC (rev 145097)
@@ -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
+
Property changes on: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename-expected.txt
___________________________________________________________________

Added: svn:mime-type

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename.html (0 => 145097)


--- trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename.html	2013-03-07 18:25:10 UTC (rev 145097)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</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=""
+</body>
+</html>
+
Property changes on: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-blob-filename.html
___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt (0 => 145097)


--- trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt	2013-03-07 18:25:10 UTC (rev 145097)
@@ -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
+
Property changes on: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename-expected.txt
___________________________________________________________________

Added: svn:mime-type

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename.html (0 => 145097)


--- trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename.html	2013-03-07 18:25:10 UTC (rev 145097)
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src=""
+<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=""
+</body>
+</html>
+
Property changes on: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-file-filename.html
___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/http/tests/xmlhttprequest/resources/multipart-post-echo-filenames.php (0 => 145097)


--- trunk/LayoutTests/http/tests/xmlhttprequest/resources/multipart-post-echo-filenames.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/resources/multipart-post-echo-filenames.php	2013-03-07 18:25:10 UTC (rev 145097)
@@ -0,0 +1,9 @@
+<?php
+$first = True;
+foreach ($_FILES as $file) {
+    if (!$first)
+        echo ",";
+    echo $file['name'];
+    $first = False;
+}
+?>

Modified: trunk/LayoutTests/platform/wk2/TestExpectations (145096 => 145097)


--- trunk/LayoutTests/platform/wk2/TestExpectations	2013-03-07 18:23:47 UTC (rev 145096)
+++ trunk/LayoutTests/platform/wk2/TestExpectations	2013-03-07 18:25:10 UTC (rev 145097)
@@ -868,6 +868,7 @@
 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

Modified: trunk/Source/WebCore/ChangeLog (145096 => 145097)


--- trunk/Source/WebCore/ChangeLog	2013-03-07 18:23:47 UTC (rev 145096)
+++ trunk/Source/WebCore/ChangeLog	2013-03-07 18:25:10 UTC (rev 145097)
@@ -1,3 +1,20 @@
+2013-03-07  Alexey Proskuryakov  <a...@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
+
+        * html/FileInputType.cpp: (WebCore::FileInputType::appendFormData):
+        Use a Blob for empty file input, not a hacky File with empty path.
+
+        * 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  Andrey Lushnikov  <lushni...@chromium.org>
 
         Web Inspector: [CodeMirror] dublicated horizontal scroll

Modified: trunk/Source/WebCore/html/FileInputType.cpp (145096 => 145097)


--- trunk/Source/WebCore/html/FileInputType.cpp	2013-03-07 18:23:47 UTC (rev 145096)
+++ trunk/Source/WebCore/html/FileInputType.cpp	2013-03-07 18:25:10 UTC (rev 145097)
@@ -40,6 +40,7 @@
 #include "RenderFileUploadControl.h"
 #include "ScriptController.h"
 #include "ShadowRoot.h"
+#include "WebKitBlobBuilder.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/text/StringBuilder.h>
 #include <wtf/text/WTFString.h>
@@ -154,7 +155,7 @@
     // If no filename at all is entered, return successful but empty.
     // Null would be more logical, but Netscape posts an empty file. Argh.
     if (!numFiles) {
-        encoding.appendBlob(element()->name(), File::create(""));
+        encoding.appendBlob(element()->name(), BlobBuilder().getBlob(ASCIILiteral("application/octet-stream")), emptyString());
         return true;
     }
 

Modified: trunk/Source/WebCore/platform/network/FormData.cpp (145096 => 145097)


--- trunk/Source/WebCore/platform/network/FormData.cpp	2013-03-07 18:23:47 UTC (rev 145096)
+++ trunk/Source/WebCore/platform/network/FormData.cpp	2013-03-07 18:25:10 UTC (rev 145097)
@@ -244,11 +244,11 @@
                     }
 
                     // 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";
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to