aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/stylesheet_loader.rs
diff options
context:
space:
mode:
authorVincent Ricard <ghostd@users.noreply.github.com>2025-05-19 13:38:01 +0200
committerGitHub <noreply@github.com>2025-05-19 11:38:01 +0000
commit6e97fc0bc47b6c3c5af9b1750f01f268b6b200f5 (patch)
tree66ed4fced2f39f7cebda142057c516c821226309 /components/script/stylesheet_loader.rs
parentd8837e4a52583bfa5e519017026c3e5b58451ac5 (diff)
downloadservo-6e97fc0bc47b6c3c5af9b1750f01f268b6b200f5.tar.gz
servo-6e97fc0bc47b6c3c5af9b1750f01f268b6b200f5.zip
Use spec compliant content-type extraction in more places and enable a `<stylesheet>` quirk (#28321)
This changes includes two semi-related things: 1. Fixes some specification compliance issues when parsing mime types and charsets for `XMLHttpRequest`. 2. Implements a `<stylesheet>` parsing quirk involving mime types. Testing: There are tests for these changes. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/stylesheet_loader.rs')
-rw-r--r--components/script/stylesheet_loader.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs
index a18d63e323b..5efaf78e542 100644
--- a/components/script/stylesheet_loader.rs
+++ b/components/script/stylesheet_loader.rs
@@ -163,7 +163,8 @@ impl FetchResponseListener for StylesheetContext {
Some(meta) => meta,
None => return,
};
- let is_css = metadata.content_type.is_some_and(|ct| {
+
+ let mut is_css = metadata.content_type.is_some_and(|ct| {
let mime: Mime = ct.into_inner().into();
mime.type_() == mime::TEXT && mime.subtype() == mime::CSS
}) || (
@@ -177,6 +178,17 @@ impl FetchResponseListener for StylesheetContext {
document.origin().immutable().clone() == metadata.final_url.origin()
);
+ // From <https://html.spec.whatwg.org/multipage/#link-type-stylesheet>:
+ // > 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.
+ if document.quirks_mode() == QuirksMode::Quirks &&
+ document.url().origin() == self.url.origin()
+ {
+ is_css = true;
+ }
+
let data = if is_css {
let data = std::mem::take(&mut self.data);
self.unminify_css(data, metadata.final_url.clone())