Bug 1459859 - Treat an empty <input type=file> as an empty File in FormData. r=smaug,robwu
This patch changes the value of an empty `<input type=file>` control as obtained from the `FormData` API, which used to be an empty string, to be a `File` object with empty contents, whose name is the empty string and whose type is `"application/octet-stream"`. Differential Revision: https://phabricator.services.mozilla.com/D106605
This commit is contained in:
@@ -5668,13 +5668,21 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission) {
|
||||
GetFilesOrDirectoriesInternal();
|
||||
|
||||
if (files.IsEmpty()) {
|
||||
aFormSubmission->AddNameBlobOrNullPair(name, nullptr);
|
||||
return NS_OK;
|
||||
ErrorResult rv;
|
||||
RefPtr<Blob> blob = Blob::CreateStringBlob(
|
||||
GetOwnerGlobal(), ""_ns, u"application/octet-stream"_ns);
|
||||
RefPtr<File> file = blob->ToFile(u""_ns, rv);
|
||||
|
||||
if (!rv.Failed()) {
|
||||
aFormSubmission->AddNameBlobPair(name, file);
|
||||
}
|
||||
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < files.Length(); ++i) {
|
||||
if (files[i].IsFile()) {
|
||||
aFormSubmission->AddNameBlobOrNullPair(name, files[i].GetAsFile());
|
||||
aFormSubmission->AddNameBlobPair(name, files[i].GetAsFile());
|
||||
} else {
|
||||
MOZ_ASSERT(files[i].IsDirectory());
|
||||
aFormSubmission->AddNameDirectoryPair(name, files[i].GetAsDirectory());
|
||||
|
||||
Reference in New Issue
Block a user