Commit 7484a1f 1 parent 3a2533f commit 7484a1f Copy full SHA for 7484a1f
File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,12 @@ impl TokenSink for LinkExtractor {
86
86
}
87
87
}
88
88
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
+
89
95
for attr in attrs {
90
96
let urls = LinkExtractor :: extract_urls_from_elem_attr (
91
97
& attr. name . local ,
@@ -416,6 +422,16 @@ mod tests {
416
422
assert ! ( uris. is_empty( ) ) ;
417
423
}
418
424
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
+
419
435
#[ test]
420
436
fn test_ignore_text_content_links ( ) {
421
437
let input = r#"
Original file line number Diff line number Diff line change @@ -178,6 +178,11 @@ impl LinkExtractor {
178
178
return ;
179
179
}
180
180
181
+ if self . current_attributes . contains_key ( "prefix" ) {
182
+ self . current_attributes . clear ( ) ;
183
+ return ;
184
+ }
185
+
181
186
let new_urls = self
182
187
. extract_urls_from_elem_attr ( )
183
188
. into_iter ( )
@@ -613,6 +618,16 @@ mod tests {
613
618
assert ! ( uris. is_empty( ) ) ;
614
619
}
615
620
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
+
616
631
#[ test]
617
632
fn test_ignore_text_content_links ( ) {
618
633
let input = r#"
You can’t perform that action at this time.
0 commit comments