From f55471333bfafaf417c001c138fba0d857206426 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 13 Mar 2024 16:05:32 -0400 Subject: [PATCH] LibWeb: Set the MIME type when creating an element's File list We were passing the MIME type to the underlying Blob, but the factory for creating a File only checks an explicit options structure. --- Tests/LibWeb/Text/expected/input-file.txt | 20 +++++++++---------- Tests/LibWeb/Text/input/input-file.html | 4 ++-- .../LibWeb/HTML/HTMLInputElement.cpp | 6 +++++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Tests/LibWeb/Text/expected/input-file.txt b/Tests/LibWeb/Text/expected/input-file.txt index dda004e38d6..5c523a76f5e 100644 --- a/Tests/LibWeb/Text/expected/input-file.txt +++ b/Tests/LibWeb/Text/expected/input-file.txt @@ -1,12 +1,12 @@ Select file...file1 Select files...4 files selected. input1: -file1 (index iteration): Contents for file1 -file1 (for..of iteration): Contents for file1 +file1 (index iteration): text/plain: Contents for file1 +file1 (for..of iteration): text/plain: Contents for file1 input2: -file1 (index iteration): Contents for file1 -file2 (index iteration): Contents for file2 -file3 (index iteration): Contents for file3 -file4 (index iteration): Contents for file4 -file1 (for..of iteration): Contents for file1 -file2 (for..of iteration): Contents for file2 -file3 (for..of iteration): Contents for file3 -file4 (for..of iteration): Contents for file4 +file1 (index iteration): text/plain: Contents for file1 +file2 (index iteration): text/plain: Contents for file2 +file3 (index iteration): text/plain: Contents for file3 +file4 (index iteration): text/plain: Contents for file4 +file1 (for..of iteration): text/plain: Contents for file1 +file2 (for..of iteration): text/plain: Contents for file2 +file3 (for..of iteration): text/plain: Contents for file3 +file4 (for..of iteration): text/plain: Contents for file4 diff --git a/Tests/LibWeb/Text/input/input-file.html b/Tests/LibWeb/Text/input/input-file.html index 46d41c517cc..f569a13ec44 100644 --- a/Tests/LibWeb/Text/input/input-file.html +++ b/Tests/LibWeb/Text/input/input-file.html @@ -13,13 +13,13 @@ const file = input.files.item(i); const text = await file.text(); - println(`${file.name} (index iteration): ${text}`); + println(`${file.name} (index iteration): ${file.type}: ${text}`); } for (let file of input.files) { const text = await file.text(); - println(`${file.name} (for..of iteration): ${text}`); + println(`${file.name} (for..of iteration): ${file.type}: ${text}`); } resolve(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index be5db5361e5..bd499a25bdb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -422,7 +422,11 @@ void HTMLInputElement::did_select_files(Span selected_files) // FIXME: The FileAPI should use ByteString for file names. auto file_name = MUST(String::from_byte_string(selected_file.name())); - auto file = MUST(FileAPI::File::create(realm(), { JS::make_handle(blob) }, file_name)); + // FIXME: Fill in other fields (e.g. last_modified). + FileAPI::FilePropertyBag options {}; + options.type = mime_type.essence(); + + auto file = MUST(FileAPI::File::create(realm(), { JS::make_handle(blob) }, file_name, move(options))); files.unchecked_append(file); }