Filename passed to FormData.append() takes precedence over filename in
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2013 22:28:11 +0000 (22:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2013 22:28:11 +0000 (22:28 +0000)
File.
https://bugs.webkit.org/show_bug.cgi?id=111255

Patch by Victor Costan <costan@gmail.com> on 2013-03-04
Reviewed by Alexey Proskuryakov.

Source/WebCore:

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

* platform/network/FormData.cpp:
(WebCore::FormData::appendKeyValuePairItems): changed to implement the
behavior in the XMLHttpRequest W3C spec.

LayoutTests:

(runTest):
* http/tests/local/formdata/send-form-data-with-filename-expected.txt: Added.
* http/tests/local/formdata/send-form-data-with-filename.html: Added.
* http/tests/local/formdata/send-form-data-with-sliced-file-expected.txt: Updated
to reflect the behavior specified in the XMLHttpRequest W3C spec.
* platform/wk2/TestExpectations: newly added test doesn't work in
WebKit2 because beginDragWithFiles is not implemented

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

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

index 9358038..eeeb31c 100644 (file)
@@ -1,3 +1,19 @@
+2013-03-04  Victor Costan <costan@gmail.com>
+
+        Filename passed to FormData.append() takes precedence over filename in
+        File.
+        https://bugs.webkit.org/show_bug.cgi?id=111255
+
+        Reviewed by Alexey Proskuryakov.
+
+        (runTest):
+        * http/tests/local/formdata/send-form-data-with-filename-expected.txt: Added.
+        * http/tests/local/formdata/send-form-data-with-filename.html: Added.
+        * http/tests/local/formdata/send-form-data-with-sliced-file-expected.txt: Updated
+        to reflect the behavior specified in the XMLHttpRequest W3C spec.
+        * platform/wk2/TestExpectations: newly added test doesn't work in
+        WebKit2 because beginDragWithFiles is not implemented
+
 2013-03-04  Alexis Hetu  <sugoi@chromium.org>
 
         Canvas and DOM go out of sync
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-filename-expected.txt b/LayoutTests/http/tests/local/formdata/send-form-data-with-filename-expected.txt
new file mode 100644 (file)
index 0000000..1a9de35
--- /dev/null
@@ -0,0 +1,11 @@
+Test for sending FormData via XMLHttpRequest.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Sending FormData containing one file with custom filename:
+file1=custom-name.txt:text/plain:1234567890
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-filename.html b/LayoutTests/http/tests/local/formdata/send-form-data-with-filename.html
new file mode 100644 (file)
index 0000000..3ca00f5
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<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 for sending FormData via XMLHttpRequest.");
+
+function runTest()
+{
+    debug("Sending FormData containing one file with custom filename:");
+    testSendingFormData([
+        { 'type': 'file', 'name': 'file1', 'value': '../resources/file-for-drag-to-send.txt', 'filename': 'custom-name.txt' }
+    ]);
+}
+
+if (window.eventSender) {
+    runTest();
+    formDataTestingCleanup();
+} else {
+    testFailed("This test is not interactive, please run using DumpRenderTree");
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
+
index 0deff12..e51921b 100644 (file)
@@ -12,7 +12,7 @@ file=blob:application/octet-stream:23456
 Sending FormData containing one sliced file with optional non-null filename:
 file=filename:application/octet-stream:23456
 Sending FormData containing one complete file with optional non-null filename:
-file=file-for-drag-to-send.txt:text/plain:1234567890
+file=filename:text/plain:1234567890
 Sending FormData containing one string and one sliced file:
 string1=foo&file1=blob:application/octet-stream:23456
 Sending FormData containing two strings and two sliced files:
index 5b98691..6c8b842 100644 (file)
@@ -6,13 +6,13 @@
 # are met:
 #
 # 1.  Redistributions of source code must retain the above copyright
-#     notice, this list of conditions and the following disclaimer. 
+#     notice, this list of conditions and the following disclaimer.
 # 2.  Redistributions in binary form must reproduce the above copyright
 #     notice, this list of conditions and the following disclaimer in the
-#     documentation and/or other materials provided with the distribution. 
+#     documentation and/or other materials provided with the distribution.
 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 #     its contributors may be used to endorse or promote products derived
-#     from this software without specific prior written permission. 
+#     from this software without specific prior written permission.
 #
 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -58,7 +58,7 @@ platform/mac/accessibility/iframe-with-title-correct-hierarchy.html
 # Some compositing tests flakey
 # <https://bugs.webkit.org/show_bug.cgi?id=48354>
 compositing/iframes/iframe-size-from-zero.html
-compositing/iframes/iframe-src-change.html 
+compositing/iframes/iframe-src-change.html
 
 # Flakey on Snow Leopard Intel WebKit2 Release Tests
 # <https://bugs.webkit.org/show_bug.cgi?id=57638>
@@ -78,7 +78,7 @@ http/tests/inspector/extensions-headers.html
 http/tests/inspector/extensions-network-redirect.html
 
 # Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
-inspector/extensions/extensions-eval-content-script.html 
+inspector/extensions/extensions-eval-content-script.html
 inspector/extensions/extensions-audits-content-script.html
 
 # A bunch of inspector tests time out on Lion Intel Debug WebKit2 testers.
@@ -881,6 +881,7 @@ http/tests/local/fileapi/file-last-modified.html
 http/tests/local/fileapi/send-dragged-file.html
 http/tests/local/formdata/form-data-with-unknown-file-extension.html
 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/upload-events.html
index 2ed2b8a..718f72d 100644 (file)
@@ -1,3 +1,17 @@
+2013-03-04  Victor Costan <costan@gmail.com>
+
+        Filename passed to FormData.append() takes precedence over filename in
+        File.
+        https://bugs.webkit.org/show_bug.cgi?id=111255
+
+        Reviewed by Alexey Proskuryakov.
+
+        Test: http/tests/local/formdata/send-form-data-with-filename.html
+
+        * platform/network/FormData.cpp:
+        (WebCore::FormData::appendKeyValuePairItems): changed to implement the
+        behavior in the XMLHttpRequest W3C spec.
+
 2013-03-04  Alexis Hetu  <sugoi@chromium.org>
 
         Canvas and DOM go out of sync
index 54b573e..381d17b 100644 (file)
@@ -242,6 +242,10 @@ void FormData::appendKeyValuePairItems(const FormDataList& list, const TextEncod
                                 name = generatedFileName;
                         }
                     }
+
+                    // If a filename is passed in FormData.append(), use it instead of the file blob's name.
+                    if (!value.filename().isEmpty())
+                        name = value.filename();
                 } else {
                     // For non-file blob, use the filename if it is passed in FormData.append().
                     if (!value.filename().isEmpty())