mirror of
https://github.com/getzola/zola
synced 2025-01-22 16:45:12 +00:00
Properly escape anchor names (#1908)
This commit is contained in:
parent
afc6a71a79
commit
4f6a1c6bcc
1 changed files with 8 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
use libs::regex::Regex;
|
use libs::regex::Regex;
|
||||||
|
use libs::regex::escape;
|
||||||
|
|
||||||
pub fn has_anchor_id(content: &str, anchor: &str) -> bool {
|
pub fn has_anchor_id(content: &str, anchor: &str) -> bool {
|
||||||
let checks = anchor_id_checks(anchor);
|
let checks = anchor_id_checks(anchor);
|
||||||
|
@ -6,7 +7,8 @@ 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#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#, anchor)).unwrap()
|
Regex::new(&format!(r#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#,
|
||||||
|
escape(anchor))).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -44,7 +46,11 @@ mod tests {
|
||||||
assert!(m(r#"<a
|
assert!(m(r#"<a
|
||||||
id="fred">"#));
|
id="fred">"#));
|
||||||
|
|
||||||
|
// Escaped Anchors
|
||||||
|
assert!(check("fred?george", r#"<a id="fred?george">"#));
|
||||||
|
assert!(check("fred.george", r#"<a id="fred.george">"#));
|
||||||
|
|
||||||
// Non matchers
|
// Non matchers
|
||||||
assert!(!m(r#"<a notid="fred">"#))
|
assert!(!m(r#"<a notid="fred">"#));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue