mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-16 20:50:25 +00:00
feat: respect the disabled property for stylesheet links (#1716)
Signed-off-by: Keming <kemingy94@gmail.com>
This commit is contained in:
parent
b128b86a48
commit
1c97f26aa2
2 changed files with 45 additions and 0 deletions
|
|
@ -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#"
|
||||
<link rel="stylesheet" href="https://disabled.com" disabled>
|
||||
<link rel="stylesheet" href="https://disabled.com" disabled="disabled">
|
||||
<a href="https://example.org">i'm fine</a>
|
||||
"#;
|
||||
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#"<!DOCTYPE html>
|
||||
|
|
|
|||
|
|
@ -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#"
|
||||
<link rel="stylesheet" href="https://disabled.com" disabled>
|
||||
<link rel="stylesheet" href="https://disabled.com" disabled="disabled">
|
||||
<a href="https://example.org">i'm fine</a>
|
||||
"#;
|
||||
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#"<!DOCTYPE html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue