mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-19 04:31:05 +00:00
feat: Add tests for dns-prefetch (#1522)
* Exclude `rel=dns-prefetch` links Resolves #1499 * Add tests for dns-prefetch --------- Co-authored-by: wackget <136205263+wackget@users.noreply.github.com>
This commit is contained in:
parent
e398325bb0
commit
913cf717a4
2 changed files with 45 additions and 4 deletions
|
|
@ -413,4 +413,24 @@ mod tests {
|
|||
let uris = extract_html(input, false);
|
||||
assert!(uris.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_dns_prefetch() {
|
||||
let input = r#"
|
||||
<link rel="dns-prefetch" href="https://example.com">
|
||||
"#;
|
||||
|
||||
let uris = extract_html(input, false);
|
||||
assert!(uris.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_dns_prefetch_reverse_order() {
|
||||
let input = r#"
|
||||
<link href="https://example.com" rel="dns-prefetch">
|
||||
"#;
|
||||
|
||||
let uris = extract_html(input, false);
|
||||
assert!(uris.is_empty());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,8 +151,8 @@ impl LinkExtractor {
|
|||
/// Here are the rules for extracting links:
|
||||
/// - If the current element has a `rel=nofollow` attribute, the current attribute
|
||||
/// value is ignored.
|
||||
/// - If the current element has a `rel=preconnect` attribute, the current attribute
|
||||
/// value is ignored.
|
||||
/// - If the current element has a `rel=preconnect` or `rel=dns-prefetch`
|
||||
/// attribute, the current attribute value is ignored.
|
||||
/// - If the current attribute value is not a URL, it is treated as plain text and
|
||||
/// added to the links vector.
|
||||
/// - If the current attribute name is `id`, the current attribute value is added
|
||||
|
|
@ -170,8 +170,9 @@ impl LinkExtractor {
|
|||
}
|
||||
|
||||
if self.current_attributes.get("rel").map_or(false, |rel| {
|
||||
rel.split(',')
|
||||
.any(|r| r.trim() == "nofollow" || r.trim() == "preconnect")
|
||||
rel.split(',').any(|r| {
|
||||
r.trim() == "nofollow" || r.trim() == "preconnect" || r.trim() == "dns-prefetch"
|
||||
})
|
||||
}) {
|
||||
self.current_attributes.clear();
|
||||
return;
|
||||
|
|
@ -607,4 +608,24 @@ mod tests {
|
|||
let uris = extract_html(input, false);
|
||||
assert!(uris.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_dns_prefetch() {
|
||||
let input = r#"
|
||||
<link rel="dns-prefetch" href="https://example.com">
|
||||
"#;
|
||||
|
||||
let uris = extract_html(input, false);
|
||||
assert!(uris.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_dns_prefetch_reverse_order() {
|
||||
let input = r#"
|
||||
<link href="https://example.com" rel="dns-prefetch">
|
||||
"#;
|
||||
|
||||
let uris = extract_html(input, false);
|
||||
assert!(uris.is_empty());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue