Fix: Add support for stylesheet MIME type quirk in quirks mode (#36338)

This PR implements the HTML spec quirk for stylesheets:
https://html.spec.whatwg.org/multipage/#link-type-stylesheet

The implementation adds a check in `stylesheet_loader.rs` to handle this
quirk condition correctly, and adds a new WPT test to verify that
same-origin non-CSS MIME type resources are properly treated as CSS in
quirks mode.

Testing: Added a new WPT test (`quirk-origin-check-positive.html`) that
verifies the positive case for this quirk.
Fixes: https://github.com/servo/servo/issues/36324

---------

Signed-off-by: saku-1101 <sakupi1101@outlook.jp>
This commit is contained in:
saku 2025-04-06 09:28:35 +09:00 committed by GitHub
parent 6031a12fd1
commit b4fd9ebb0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 1 deletions

View file

@ -15,6 +15,7 @@ use net_traits::{
};
use servo_arc::Arc;
use servo_url::ServoUrl;
use style::context::QuirksMode;
use style::media_queries::MediaList;
use style::parser::ParserContext;
use style::shared_lock::{Locked, SharedRwLock};
@ -164,7 +165,16 @@ impl FetchResponseListener for StylesheetContext {
let is_css = metadata.content_type.is_some_and(|ct| {
let mime: Mime = ct.into_inner().into();
mime.type_() == mime::TEXT && mime.subtype() == mime::CSS
});
}) || (
// 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.
// <https://html.spec.whatwg.org/multipage/#link-type-stylesheet>
document.quirks_mode() == QuirksMode::Quirks &&
document.origin().immutable().clone() == metadata.final_url.origin()
);
let data = if is_css {
let data = std::mem::take(&mut self.data);