Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(css): parse stylesheet preload type hints as MIME values

ldm06ecf3f0c037f
diff --git a/Cargo.lock b/Cargo.lock
index 969d81080..2833c7410 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3278,6 +3278,7 @@ dependencies = [
"moli-owner-queue",
"moli-page-types",
"moli-time",
+ "moli-web-mime",
"tokio",
"url",
]
diff --git a/moli-stylesheet-blocking/Cargo.toml b/moli-stylesheet-blocking/Cargo.toml
index c0b80b1ed..3bd639ae8 100644
--- a/moli-stylesheet-blocking/Cargo.toml
+++ b/moli-stylesheet-blocking/Cargo.toml
@@ -11,6 +11,7 @@ moli-fetch = { path = "../moli-fetch" }
moli-owner-queue = { path = "../moli-owner-queue" }
moli-page-types = { path = "../moli-page-types" }
moli-time = { path = "../moli-time" }
+moli-web-mime = { path = "../moli-web-mime" }
tokio = { version = "1.51.0", features = ["rt", "sync"] }
url = "2.5.7"
diff --git a/moli-stylesheet-blocking/src/discovery.rs b/moli-stylesheet-blocking/src/discovery.rs
index d7b4373c4..344d91d24 100644
--- a/moli-stylesheet-blocking/src/discovery.rs
+++ b/moli-stylesheet-blocking/src/discovery.rs
@@ -359,7 +359,10 @@ pub fn stylesheet_preload_link_request(
let element = document.stylesheet_element(native_node_id)?;
if !element.is_html_element("link")
|| element.disabled
- || !stylesheet_type_is_supported(element.type_attr.as_deref())
+ || element
+ .type_attr
+ .as_deref()
+ .is_some_and(|value| !value.is_empty() && !moli_web_mime::is_css_mime(value))
{
return None;
}
@@ -846,5 +849,21 @@ mod tests {
assert!(host.remove_attribute(link, "disabled"));
assert!(host.set_attribute(link, "type", "text/plain"));
assert!(stylesheet_preload_link_request(&host, node_id).is_none());
+
+ for value in [
+ "text/css; charset=UTF-8",
+ "\tTEXT/CSS \r\n",
+ "text/css;ignored",
+ ] {
+ assert!(host.set_attribute(link, "type", value));
+ assert!(
+ stylesheet_preload_link_request(&host, node_id).is_some(),
+ "CSS preload MIME hint {value:?} must select the typed stylesheet owner"
+ );
+ }
+ for value in [" ", "\u{a0}text/css", "text/css, text/css"] {
+ assert!(host.set_attribute(link, "type", value));
+ assert!(stylesheet_preload_link_request(&host, node_id).is_none());
+ }
}
}