diff --git a/lychee-lib/src/extract/html/html5ever.rs b/lychee-lib/src/extract/html/html5ever.rs
index 78925a3..d7fa67b 100644
--- a/lychee-lib/src/extract/html/html5ever.rs
+++ b/lychee-lib/src/extract/html/html5ever.rs
@@ -128,6 +128,11 @@ impl TokenSink for LinkExtractor {
if url.starts_with("/@") || url.starts_with('@') {
return false;
}
+ // Skip disabled stylesheets
+ // Ref: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/disabled
+ if attrs.iter().any(|attr| &attr.name.local == "disabled") {
+ return false;
+ }
}
!is_email || (is_mailto && is_href) || (is_phone && is_href)
@@ -337,6 +342,22 @@ mod tests {
assert_eq!(uris, expected);
}
+ #[test]
+ fn test_exclude_disabled_stylesheet() {
+ let input = r#"
+
+
+ i'm fine
+ "#;
+ let expected = vec![RawUri {
+ text: "https://example.org".to_string(),
+ element: Some("a".to_string()),
+ attribute: Some("href".to_string()),
+ }];
+ let uris = extract_html(input, false);
+ assert_eq!(uris, expected);
+ }
+
#[test]
fn test_valid_email() {
let input = r#"
diff --git a/lychee-lib/src/extract/html/html5gum.rs b/lychee-lib/src/extract/html/html5gum.rs
index 8ff13d9..0c86aa1 100644
--- a/lychee-lib/src/extract/html/html5gum.rs
+++ b/lychee-lib/src/extract/html/html5gum.rs
@@ -197,6 +197,14 @@ impl LinkExtractor {
return;
}
}
+ // Skip disabled stylesheets
+ // Ref: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/disabled
+ if self.current_attribute_name == "disabled"
+ || self.current_attributes.contains_key("disabled")
+ {
+ self.current_attributes.clear();
+ return;
+ }
}
let new_urls = self
@@ -517,6 +525,22 @@ mod tests {
assert_eq!(uris, expected);
}
+ #[test]
+ fn test_exclude_disabled_stylesheet() {
+ let input = r#"
+
+
+ i'm fine
+ "#;
+ let expected = vec![RawUri {
+ text: "https://example.org".to_string(),
+ element: Some("a".to_string()),
+ attribute: Some("href".to_string()),
+ }];
+ let uris = extract_html(input, false);
+ assert_eq!(uris, expected);
+ }
+
#[test]
fn test_valid_tel() {
let input = r#"