diff --git a/components/script/body.rs b/components/script/body.rs index ec51a7fe0ea..119ad294753 100644 --- a/components/script/body.rs +++ b/components/script/body.rs @@ -737,8 +737,15 @@ fn run_package_data_algorithm( /// fn run_text_data_algorithm(bytes: Vec) -> Fallible { + // This implements the Encoding standard's "decode UTF-8", which removes the + // BOM if present. + let no_bom_bytes = if bytes.starts_with(b"\xEF\xBB\xBF") { + &bytes[3..] + } else { + &bytes + }; Ok(FetchedData::Text( - String::from_utf8_lossy(&bytes).into_owned(), + String::from_utf8_lossy(no_bom_bytes).into_owned(), )) } diff --git a/tests/wpt/meta/fetch/api/basic/text-utf8.any.js.ini b/tests/wpt/meta/fetch/api/basic/text-utf8.any.js.ini index 4a8e2275aca..6f7d3185d2c 100644 --- a/tests/wpt/meta/fetch/api/basic/text-utf8.any.js.ini +++ b/tests/wpt/meta/fetch/api/basic/text-utf8.any.js.ini @@ -1,30 +1,6 @@ [text-utf8.any.html] - [UTF-8 with BOM with Request.text()] - expected: FAIL - - [UTF-8 with BOM with fetched data (UTF-16 charset)] - expected: FAIL - - [UTF-8 with BOM with fetched data (UTF-8 charset)] - expected: FAIL - - [UTF-8 with BOM with Response.text()] - expected: FAIL - [text-utf8.any.worker.html] - [UTF-8 with BOM with Request.text()] - expected: FAIL - - [UTF-8 with BOM with fetched data (UTF-16 charset)] - expected: FAIL - - [UTF-8 with BOM with fetched data (UTF-8 charset)] - expected: FAIL - - [UTF-8 with BOM with Response.text()] - expected: FAIL - [text-utf8.any.serviceworker.html] expected: ERROR diff --git a/tests/wpt/meta/fetch/metadata/trailing-dot.https.sub.any.js.ini b/tests/wpt/meta/fetch/metadata/trailing-dot.https.sub.any.js.ini index c52790a949e..c1466f6ca10 100644 --- a/tests/wpt/meta/fetch/metadata/trailing-dot.https.sub.any.js.ini +++ b/tests/wpt/meta/fetch/metadata/trailing-dot.https.sub.any.js.ini @@ -8,36 +8,18 @@ [Fetching a resource from the same origin, but spelled with a trailing dot.] expected: FAIL - [Fetching a resource from the same origin, but spelled with a trailing dot.: sec-fetch-dest] - expected: FAIL - - [Fetching a resource from the same origin, but spelled with a trailing dot.: sec-fetch-mode] - expected: FAIL - [Fetching a resource from the same origin, but spelled with a trailing dot.: sec-fetch-site] expected: FAIL [Fetching a resource from the same site, but spelled with a trailing dot.] expected: FAIL - [Fetching a resource from the same site, but spelled with a trailing dot.: sec-fetch-dest] - expected: FAIL - - [Fetching a resource from the same site, but spelled with a trailing dot.: sec-fetch-mode] - expected: FAIL - [Fetching a resource from the same site, but spelled with a trailing dot.: sec-fetch-site] expected: FAIL [Fetching a resource from a cross-site host, spelled with a trailing dot.] expected: FAIL - [Fetching a resource from a cross-site host, spelled with a trailing dot.: sec-fetch-dest] - expected: FAIL - - [Fetching a resource from a cross-site host, spelled with a trailing dot.: sec-fetch-mode] - expected: FAIL - [Fetching a resource from a cross-site host, spelled with a trailing dot.: sec-fetch-site] expected: FAIL @@ -46,35 +28,17 @@ [Fetching a resource from the same origin, but spelled with a trailing dot.] expected: FAIL - [Fetching a resource from the same origin, but spelled with a trailing dot.: sec-fetch-dest] - expected: FAIL - - [Fetching a resource from the same origin, but spelled with a trailing dot.: sec-fetch-mode] - expected: FAIL - [Fetching a resource from the same origin, but spelled with a trailing dot.: sec-fetch-site] expected: FAIL [Fetching a resource from the same site, but spelled with a trailing dot.] expected: FAIL - [Fetching a resource from the same site, but spelled with a trailing dot.: sec-fetch-dest] - expected: FAIL - - [Fetching a resource from the same site, but spelled with a trailing dot.: sec-fetch-mode] - expected: FAIL - [Fetching a resource from the same site, but spelled with a trailing dot.: sec-fetch-site] expected: FAIL [Fetching a resource from a cross-site host, spelled with a trailing dot.] expected: FAIL - [Fetching a resource from a cross-site host, spelled with a trailing dot.: sec-fetch-dest] - expected: FAIL - - [Fetching a resource from a cross-site host, spelled with a trailing dot.: sec-fetch-mode] - expected: FAIL - [Fetching a resource from a cross-site host, spelled with a trailing dot.: sec-fetch-site] expected: FAIL