Commit 5b7648dc authored by Amos Lim's avatar Amos Lim Committed by Commit Bot

Set "application/octet-stream" content type for empty <input type=file>

Empty <input type=file> is represented incorrectly in FormData.
If there are no selected files, then append an entry to entry
list with name and a new File object with an empty name,
application/octet-stream as type, and an empty body [1].

[1] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set

Bug: 840714
Change-Id: Ifadade1e260e0314664549df2d35f0cd38c76bea
Reviewed-on: https://chromium-review.googlesource.com/1140236Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575931}
parent 21289d5b
This is a testharness.js-based test.
FAIL Empty <input type=file> is still serialized assert_equals: type expected "application/octet-stream" but got ""
Harness: the test ran to completion.
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "third_party/blink/renderer/core/fileapi/file.h" #include "third_party/blink/renderer/core/fileapi/file.h"
#include <memory> #include <memory>
#include "third_party/blink/public/platform/file_path_conversion.h" #include "third_party/blink/public/platform/file_path_conversion.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/core/fileapi/file_property_bag.h" #include "third_party/blink/renderer/core/fileapi/file_property_bag.h"
...@@ -69,6 +70,11 @@ static std::unique_ptr<BlobData> CreateBlobDataForFileWithType( ...@@ -69,6 +70,11 @@ static std::unique_ptr<BlobData> CreateBlobDataForFileWithType(
static std::unique_ptr<BlobData> CreateBlobDataForFile( static std::unique_ptr<BlobData> CreateBlobDataForFile(
const String& path, const String& path,
File::ContentTypeLookupPolicy policy) { File::ContentTypeLookupPolicy policy) {
if (path.IsEmpty()) {
std::unique_ptr<BlobData> blob_data = BlobData::Create();
blob_data->SetContentType("application/octet-stream");
return blob_data;
}
return CreateBlobDataForFileWithType( return CreateBlobDataForFileWithType(
path, GetContentTypeFromFileName(path, policy)); path, GetContentTypeFromFileName(path, policy));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment