Truly independent web browser
LibWeb: Apply the same-origin quirks stylesheet MIME exception
Andreas Kling9d6a90af2870
diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cppindex 4d1899d8d7e..98c7f22dbb8 100644--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp@@ -16,6 +16,7 @@#include <LibHTTP/Header.h>#include <LibHTTP/HeaderList.h>#include <LibTextCodec/Decoder.h>+#include <LibURL/Origin.h>#include <LibURL/URL.h>#include <LibWeb/CSS/Parser/Parser.h>#include <LibWeb/CSS/StyleScope.h>@@ -1428,7 +1429,13 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastrumime_type_charset = charset->bytes_as_string_view();}- if (mime_type_string.has_value() && mime_type_string != u"text/css"sv)+ // Quirk: If the document has been set to quirks mode, has the same origin as the URL of the external resource,+ // and the Content-Type metadata of the external resource is not a supported style sheet type, the user agent+ // must instead assume it to be text/css.+ auto resource_url = response.url();+ auto assume_css_in_quirks_mode = document().in_quirks_mode() && resource_url.has_value()+ && document().origin().is_same_origin(resource_url->origin());+ if (mime_type_string.has_value() && mime_type_string != u"text/css"sv && !assume_css_in_quirks_mode)success = false;// 2. If el no longer creates an external resource link that contributes to the styling processing model, ordiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txtindex ff42c136c5f..7c767abed7d 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt@@ -2,11 +2,11 @@ Harness status: OKFound 24 tests-22 Pass-2 Fail+23 Pass+1 FailPass Stylesheet loading using <link> with no Content-Type, same-origin, and no nosniffPass Stylesheet loading using <link> with no Content-Type, same-origin, and nosniff-Fail Stylesheet loading using <link> with wrong Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, same-origin, and no nosniffPass Stylesheet loading using <link> with wrong Content-Type, same-origin, and nosniffPass Stylesheet loading using <link> with broken Content-Type, same-origin, and no nosniffPass Stylesheet loading using <link> with broken Content-Type, same-origin, and nosniffdiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-quirks-crossorigin.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-quirks-crossorigin.txtindex 959b09f9975..a14f2588335 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-quirks-crossorigin.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-quirks-crossorigin.txt@@ -2,11 +2,10 @@ Harness status: OKFound 6 tests-3 Pass-3 Fail-Fail Same-origin stylesheet with wrong MIME type, no CORS-Fail Same-origin stylesheet with wrong MIME type, with CORS+6 Pass+Pass Same-origin stylesheet with wrong MIME type, no CORS+Pass Same-origin stylesheet with wrong MIME type, with CORSPass Cross-origin stylesheet with text/css, with CORSPass Cross-origin stylesheet with wrong MIME type, with CORS-Fail Cross-origin redirect to same-origin stylesheet with wrong MIME type, with CORS+Pass Cross-origin redirect to same-origin stylesheet with wrong MIME type, with CORSPass Same-origin redirect to cross-origin stylesheet with wrong MIME type, with CORS\ No newline at end of file