Truly independent web browser
LibWeb: Only lowercase the type of a Blob or File
Andreas Kling74411331d9e3
diff --git a/Libraries/LibWeb/Bindings/Rust/src/file_api/blob.rs b/Libraries/LibWeb/Bindings/Rust/src/file_api/blob.rsindex f61882dcc91..5fd6acb987d 100644--- a/Libraries/LibWeb/Bindings/Rust/src/file_api/blob.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/file_api/blob.rs@@ -13,7 +13,6 @@ use core::ptr::NonNull;use ak::{Utf16String, Utf16StringUnits};use libjs_rust::api::{MarkedVec, RawNativeFunctionResult, Trace};-use libwebcommon_rust::mime_sniff::mime_type::MimeType;use super::file::File;use crate::bindings::conversions::{BufferSource, UsvString};@@ -283,23 +282,25 @@ fn is_basic_latin(string: &Utf16String) -> bool {/// The type of a Blob or a File that is constructed with the type member of its options.pub(crate) fn type_from_options(r#type: &Utf16String) -> Utf16String {- // FIXME: 1. If the type member is provided and is not the empty string, let t be set to the type dictionary member.+ // 1. If the type member is provided and is not the empty string, let t be set to the type dictionary member.// If t contains any characters outside the range U+0020 to U+007E, then set t to the empty string and return// from these substeps.- // FIXME: 2. Convert every character in t to ASCII lowercase.-- // NOTE: The spec is out of date, and we are supposed to call into the MimeType parser here.if !is_basic_latin(r#type) {return Utf16String::default();}- let input: Vec<char> = r#type++ // 2. Convert every character in t to ASCII lowercase.+ to_ascii_lowercase(r#type)+}++/// Converts a string whose code units are all in the range U+0020 to U+007E to ASCII lowercase.+fn to_ascii_lowercase(string: &Utf16String) -> Utf16String {+ let lowercase: Vec<u8> = string.to_utf16().iter()- .map(|&code_unit| char::from(code_unit as u8))+ .map(|&code_unit| (code_unit as u8).to_ascii_lowercase()).collect();- MimeType::parse(&input).map_or_else(Utf16String::default, |mime_type| {- Utf16String::from_ascii(mime_type.serialize().as_bytes())- })+ Utf16String::from_ascii(&lowercase)}impl Blob {@@ -444,14 +445,7 @@ impl Blob {// relativeContentType to the empty string and return from these substeps:Some(content_type) if !is_basic_latin(content_type) => Utf16String::default(),// 2. Convert every character in relativeContentType to ASCII lowercase.- Some(content_type) => {- let lowercase: Vec<u8> = content_type- .to_utf16()- .iter()- .map(|&code_unit| (code_unit as u8).to_ascii_lowercase())- .collect();- Utf16String::from_ascii(&lowercase)- }+ Some(content_type) => to_ascii_lowercase(content_type),};// 5. Let span be max((relativeEnd - relativeStart), 0).diff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.txtindex 02888881bd9..82b9ee6a9ea 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.txt@@ -2,12 +2,11 @@ Harness status: OKFound 18 tests-17 Pass-1 Fail+18 PassPass Default Content-Type for Request with empty bodyPass Default Content-Type for Request with Blob body (no type set)Pass Default Content-Type for Request with Blob body (empty type)-Fail Default Content-Type for Request with Blob body (set type)+Pass Default Content-Type for Request with Blob body (set type)Pass Default Content-Type for Request with buffer source bodyPass Default Content-Type for Request with FormData bodyPass Default Content-Type for Request with URLSearchParams bodydiff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.worker.txtindex 02888881bd9..82b9ee6a9ea 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.worker.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/request/request-init-contenttype.any.worker.txt@@ -2,12 +2,11 @@ Harness status: OKFound 18 tests-17 Pass-1 Fail+18 PassPass Default Content-Type for Request with empty bodyPass Default Content-Type for Request with Blob body (no type set)Pass Default Content-Type for Request with Blob body (empty type)-Fail Default Content-Type for Request with Blob body (set type)+Pass Default Content-Type for Request with Blob body (set type)Pass Default Content-Type for Request with buffer source bodyPass Default Content-Type for Request with FormData bodyPass Default Content-Type for Request with URLSearchParams bodydiff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.txtindex bb21657aa8c..a8634686010 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.txt@@ -2,12 +2,11 @@ Harness status: OKFound 18 tests-17 Pass-1 Fail+18 PassPass Default Content-Type for Response with empty bodyPass Default Content-Type for Response with Blob body (no type set)Pass Default Content-Type for Response with Blob body (empty type)-Fail Default Content-Type for Response with Blob body (set type)+Pass Default Content-Type for Response with Blob body (set type)Pass Default Content-Type for Response with buffer source bodyPass Default Content-Type for Response with FormData bodyPass Default Content-Type for Response with URLSearchParams bodydiff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.worker.txtindex bb21657aa8c..a8634686010 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.worker.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/response/response-init-contenttype.any.worker.txt@@ -2,12 +2,11 @@ Harness status: OKFound 18 tests-17 Pass-1 Fail+18 PassPass Default Content-Type for Response with empty bodyPass Default Content-Type for Response with Blob body (no type set)Pass Default Content-Type for Response with Blob body (empty type)-Fail Default Content-Type for Response with Blob body (set type)+Pass Default Content-Type for Response with Blob body (set type)Pass Default Content-Type for Response with buffer source bodyPass Default Content-Type for Response with FormData bodyPass Default Content-Type for Response with URLSearchParams bodydiff --git a/Tests/LibWeb/Text/expected/wpt-import/xhr/setrequestheader-content-type.txt b/Tests/LibWeb/Text/expected/wpt-import/xhr/setrequestheader-content-type.txtindex 8a203d716a9..ac4386b945a 100644--- a/Tests/LibWeb/Text/expected/wpt-import/xhr/setrequestheader-content-type.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/xhr/setrequestheader-content-type.txt@@ -2,8 +2,7 @@ Harness status: OKFound 34 tests-33 Pass-1 Fail+34 PassPass setRequestHeader("") sends a blank stringPass setRequestHeader(" ") sends the string " "Pass setRequestHeader(null) sends the string "null"@@ -23,7 +22,7 @@ Pass Blob request respects setRequestHeader("") to be specifiedPass Blob request with unset type sends no Content-Type without setRequestHeader() callPass Blob request with unset type keeps setRequestHeader() Content-Type and charsetPass Blob request with set type respects setRequestHeader("") to be specified-Fail Blob request with set type uses that it for Content-Type unless setRequestHeader()+Pass Blob request with set type uses that it for Content-Type unless setRequestHeader()Pass Blob request with set type keeps setRequestHeader() Content-Type and charsetPass ArrayBuffer request respects setRequestHeader("")Pass ArrayBuffer request sends no Content-Type without setRequestHeader() call