From c1e3e74d6ee1f03764a89ef0e21f41a66ebf7508 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 7 Jan 2016 09:54:00 +0000 Subject: [PATCH] Bug 1187157 - new FormData::get() should return an empty string if the file is not set - part 1, r=smaug --- dom/base/nsFormData.cpp | 24 ++++++++++++++++++++++++ dom/base/nsFormData.h | 16 ++-------------- dom/base/test/mochitest.ini | 1 + dom/base/test/test_bug1187157.html | 21 +++++++++++++++++++++ dom/html/HTMLInputElement.cpp | 1 - 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 dom/base/test/test_bug1187157.html diff --git a/dom/base/nsFormData.cpp b/dom/base/nsFormData.cpp index c47f7a0bdb49..b0eb9ec6f268 100644 --- a/dom/base/nsFormData.cpp +++ b/dom/base/nsFormData.cpp @@ -256,6 +256,30 @@ nsFormData::GetValueAtIndex(uint32_t aIndex) const 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 diff --git a/dom/base/nsFormData.h b/dom/base/nsFormData.h index d6e06b05e52a..10d9b7089a52 100644 --- a/dom/base/nsFormData.h +++ b/dom/base/nsFormData.h @@ -52,23 +52,11 @@ private: 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); diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index ba013f8829d4..a42a7f6a3406 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -862,3 +862,4 @@ skip-if = buildapp == 'b2g' #no ssl support [test_document.all_iteration.html] [test_performance_translate.html] [test_bug1198095.html] +[test_bug1187157.html] diff --git a/dom/base/test/test_bug1187157.html b/dom/base/test/test_bug1187157.html new file mode 100644 index 000000000000..a207162503d2 --- /dev/null +++ b/dom/base/test/test_bug1187157.html @@ -0,0 +1,21 @@ + + + + + + Test for Bug 789315 + + + + +Mozilla Bug 789315 +
+ + + + + diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 93d70f78629f..cbd2b9d8c94a 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -5596,7 +5596,6 @@ HTMLInputElement::SubmitNamesValues(nsFormSubmission* aFormSubmission) // If no file was selected, pretend we had an empty file with an // empty filename. aFormSubmission->AddNameFilePair(name, nullptr); - } return NS_OK;