aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaku <sakupi1101@outlook.jp>2025-04-06 09:28:35 +0900
committerGitHub <noreply@github.com>2025-04-06 00:28:35 +0000
commitb4fd9ebb0e1d18fc9cc307990f347d4d4b5d5abb (patch)
tree2e0aa26b3f0735b361c1544a7ecfaa17bc7136bf
parent6031a12fd1fa4aee8368e0b3dc0cb792caac56bc (diff)
downloadservo-b4fd9ebb0e1d18fc9cc307990f347d4d4b5d5abb.tar.gz
servo-b4fd9ebb0e1d18fc9cc307990f347d4d4b5d5abb.zip
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>
-rw-r--r--components/script/stylesheet_loader.rs12
-rw-r--r--tests/wpt/meta/MANIFEST.json15
-rw-r--r--tests/wpt/tests/html/links/stylesheet/quirk-origin-check-positive.html18
-rw-r--r--tests/wpt/tests/html/links/stylesheet/resources/quirk-stylesheet.css.txt1
4 files changed, 45 insertions, 1 deletions
diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs
index 6290d2709cc..7c7f7f98a07 100644
--- a/components/script/stylesheet_loader.rs
+++ b/components/script/stylesheet_loader.rs
@@ -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);
diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json
index a30e793a3d4..e50b0df3481 100644
--- a/tests/wpt/meta/MANIFEST.json
+++ b/tests/wpt/meta/MANIFEST.json
@@ -474568,6 +474568,14 @@
"80fbe8db6cbfc1f6e478b6c3cc8d2ae3c707c053",
[]
]
+ },
+ "stylesheet": {
+ "resources": {
+ "quirk-stylesheet.css.txt": [
+ "d2ae382583192b0284aa44c038811e7254a9386b",
+ []
+ ]
+ }
}
},
"meta": {
@@ -719907,6 +719915,13 @@
}
},
"stylesheet": {
+ "quirk-origin-check-positive.html": [
+ "02ab832cbe207c9bbfb1d16cbdc9a685b474372c",
+ [
+ null,
+ {}
+ ]
+ ],
"quirk-origin-check-recursive-import.html": [
"c0053f1f29ad8f23dbebdd41b38dbdd8537e9e27",
[
diff --git a/tests/wpt/tests/html/links/stylesheet/quirk-origin-check-positive.html b/tests/wpt/tests/html/links/stylesheet/quirk-origin-check-positive.html
new file mode 100644
index 00000000000..02ab832cbe2
--- /dev/null
+++ b/tests/wpt/tests/html/links/stylesheet/quirk-origin-check-positive.html
@@ -0,0 +1,18 @@
+<!-- quirks -->
+<title>Same-origin stylesheet with non-CSS MIME type quirk</title>
+<link rel="help" href="https://html.spec.whatwg.org/multipage/#link-type-stylesheet">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<link rel="stylesheet" href="resources/quirk-stylesheet.css.txt">
+<p class="test">This text should be green.</p>
+<script>
+setup({ single_test: true });
+onload = () => {
+ assert_equals(
+ getComputedStyle(document.querySelector('.test')).color,
+ 'rgb(0, 128, 0)',
+ "Same-origin stylesheet with non-CSS MIME type should be applied in quirks mode"
+ );
+ done();
+};
+</script> \ No newline at end of file
diff --git a/tests/wpt/tests/html/links/stylesheet/resources/quirk-stylesheet.css.txt b/tests/wpt/tests/html/links/stylesheet/resources/quirk-stylesheet.css.txt
new file mode 100644
index 00000000000..d2ae3825831
--- /dev/null
+++ b/tests/wpt/tests/html/links/stylesheet/resources/quirk-stylesheet.css.txt
@@ -0,0 +1 @@
+.test { color: green; } \ No newline at end of file