Allow new lines before anchor (#1905)

Previously the heuristic check for links required spaces before the
attribute to ensure that attributes suffixed with `id` were not
identified. This has now been expanded to any white space character to
enable the `id` attribute to start on a new line.
This commit is contained in:
Phil Lord 2022-06-21 14:53:07 +01:00 committed by GitHub
parent 72243d9eeb
commit afc6a71a79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ pub fn has_anchor_id(content: &str, anchor: &str) -> bool {
} }
fn anchor_id_checks(anchor: &str) -> Regex { fn anchor_id_checks(anchor: &str) -> Regex {
Regex::new(&format!(r#" (?i)(id|name) *= *("|')*{}("|'| |>)+"#, anchor)).unwrap() Regex::new(&format!(r#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#, anchor)).unwrap()
} }
#[cfg(test)] #[cfg(test)]
@ -39,5 +39,12 @@ mod tests {
// Case variants // Case variants
assert!(m(r#"<a ID="fred">"#)); assert!(m(r#"<a ID="fred">"#));
assert!(m(r#"<a iD="fred">"#)); assert!(m(r#"<a iD="fred">"#));
// Newline variants
assert!(m(r#"<a
id="fred">"#));
// Non matchers
assert!(!m(r#"<a notid="fred">"#))
} }
} }