Bug 1187157 - new FormData::get() should return an empty string if the file is not set, r=smaug
☠☠ backed out by 43f10b226ee1 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 06 Jan 2016 15:42:35 +0000
changeset 278841 23974693ffc5f51babf58313b1327da89a38e8a1
parent 278840 5435dcc651f0487ec43e1610029f9c0bed1ef04e
child 278842 b193412ac8033c6d3f3dfc18881ec47cb6ea6c5b
push id29860
push usercbook@mozilla.com
push dateThu, 07 Jan 2016 10:51:20 +0000
treeherdermozilla-central@e0bcd16e1d4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1187157
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1187157 - new FormData::get() should return an empty string if the file is not set, r=smaug
dom/base/nsFormData.cpp
dom/base/nsFormData.h
dom/base/test/mochitest.ini
dom/base/test/test_bug1187157.html
--- a/dom/base/nsFormData.cpp
+++ b/dom/base/nsFormData.cpp
@@ -251,16 +251,40 @@ nsFormData::GetKeyAtIndex(uint32_t aInde
 
 const OwningFileOrUSVString&
 nsFormData::GetValueAtIndex(uint32_t aIndex) const
 {
   MOZ_ASSERT(aIndex < mFormData.Length());
   return mFormData[aIndex].value;
 }
 
+void
+nsFormData::SetNameValuePair(FormDataTuple* aData,
+                             const nsAString& aName,
+                             const nsAString& aValue)
+{
+  MOZ_ASSERT(aData);
+  aData->name = aName;
+  aData->value.SetAsUSVString() = aValue;
+}
+
+void
+nsFormData::SetNameFilePair(FormDataTuple* aData,
+                            const nsAString& aName,
+                            File* aFile)
+{
+  MOZ_ASSERT(aData);
+  aData->name = aName;
+  if (aFile) {
+    aData->value.SetAsFile() = aFile;
+  } else {
+    aData->value.SetAsUSVString() = EmptyString();
+  }
+}
+
 // -------------------------------------------------------------------------
 // nsIDOMFormData
 
 NS_IMETHODIMP
 nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
 {
   uint16_t dataType;
   nsresult rv = aValue->GetDataType(&dataType);
--- a/dom/base/nsFormData.h
+++ b/dom/base/nsFormData.h
@@ -47,33 +47,21 @@ private:
 
   // Returns the FormDataTuple to modify. This may be null, in which case
   // no element with aName was found.
   FormDataTuple*
   RemoveAllOthersAndGetFirstFormDataTuple(const nsAString& aName);
 
   void SetNameValuePair(FormDataTuple* aData,
                         const nsAString& aName,
-                        const nsAString& aValue)
-  {
-    MOZ_ASSERT(aData);
-    aData->name = aName;
-    aData->value.SetAsUSVString() = aValue;
-  }
+                        const nsAString& aValue);
 
   void SetNameFilePair(FormDataTuple* aData,
                        const nsAString& aName,
-                       File* aFile)
-  {
-    MOZ_ASSERT(aData);
-    aData->name = aName;
-    if (aFile) {
-      aData->value.SetAsFile() = aFile;
-    }
-  }
+                       File* aFile);
 
 public:
   explicit nsFormData(nsISupports* aOwner = nullptr);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFormData,
                                                          nsIDOMFormData)
 
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -857,8 +857,9 @@ support-files = worker_postMessages.js
 [test_frameLoader_switchProcess.html]
 skip-if = e10s || os != 'linux' || buildapp != 'browser'
 [test_explicit_user_agent.html]
 [test_change_policy.html]
 skip-if = buildapp == 'b2g' #no ssl support
 [test_document.all_iteration.html]
 [test_performance_translate.html]
 [test_bug1198095.html]
+[test_bug1187157.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_bug1187157.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=789315
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 789315</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=789315">Mozilla Bug 789315</a>
+<form id="a"><input name="b" type="file"/></form>
+
+<script type="text/javascript">
+  is(new FormData(document.getElementById('a')).get('b'), "", "This should return an empty string.");
+</script>
+
+</body>
+</html>