Skip to content

Commit 7484a1f

Browse files
authored
Don't check prefix attribute (#1536)
1 parent 3a2533f commit 7484a1f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lychee-lib/src/extract/html/html5ever.rs

+16
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ impl TokenSink for LinkExtractor {
8686
}
8787
}
8888

89+
// Check and exclude `prefix` attribute. This attribute is used to define a prefix
90+
// for the current element. It is not used to link to a resource.
91+
if let Some(_prefix) = attrs.iter().find(|attr| &attr.name.local == "prefix") {
92+
return TokenSinkResult::Continue;
93+
}
94+
8995
for attr in attrs {
9096
let urls = LinkExtractor::extract_urls_from_elem_attr(
9197
&attr.name.local,
@@ -416,6 +422,16 @@ mod tests {
416422
assert!(uris.is_empty());
417423
}
418424

425+
#[test]
426+
fn test_skip_prefix() {
427+
let input = r#"
428+
<html lang="en-EN" prefix="og: https://ogp.me/ns#">
429+
"#;
430+
431+
let uris = extract_html(input, false);
432+
assert!(uris.is_empty());
433+
}
434+
419435
#[test]
420436
fn test_ignore_text_content_links() {
421437
let input = r#"

lychee-lib/src/extract/html/html5gum.rs

+15
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ impl LinkExtractor {
178178
return;
179179
}
180180

181+
if self.current_attributes.contains_key("prefix") {
182+
self.current_attributes.clear();
183+
return;
184+
}
185+
181186
let new_urls = self
182187
.extract_urls_from_elem_attr()
183188
.into_iter()
@@ -613,6 +618,16 @@ mod tests {
613618
assert!(uris.is_empty());
614619
}
615620

621+
#[test]
622+
fn test_skip_prefix() {
623+
let input = r#"
624+
<html lang="en-EN" prefix="og: https://ogp.me/ns#">
625+
"#;
626+
627+
let uris = extract_html(input, false);
628+
assert!(uris.is_empty());
629+
}
630+
616631
#[test]
617632
fn test_ignore_text_content_links() {
618633
let input = r#"

0 commit comments

Comments
 (0)