Fix link checker not checking for capital id/name

Closes #948
This commit is contained in:
Vincent Prouillet 2020-03-25 19:54:22 +01:00
parent 30f6f38e6e
commit 91bf91a88b
2 changed files with 18 additions and 1 deletions

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.10.2 (unreleased)
- Fix link checker not looking for anchor with capital id/name
## 0.10.1 (2020-03-12) ## 0.10.1 (2020-03-12)
- Set user agent for HTTP requests - Set user agent for HTTP requests

View file

@ -118,11 +118,15 @@ fn has_anchor(url: &str) -> bool {
fn check_page_for_anchor(url: &str, body: String) -> Result<()> { fn check_page_for_anchor(url: &str, body: String) -> Result<()> {
let index = url.find('#').unwrap(); let index = url.find('#').unwrap();
let anchor = url.get(index + 1..).unwrap(); let anchor = url.get(index + 1..).unwrap();
let checks: [String; 4] = [ let checks: [String; 8] = [
format!(" id='{}'", anchor), format!(" id='{}'", anchor),
format!(" ID='{}'", anchor),
format!(r#" id="{}""#, anchor), format!(r#" id="{}""#, anchor),
format!(r#" ID="{}""#, anchor),
format!(" name='{}'", anchor), format!(" name='{}'", anchor),
format!(" NAME='{}'", anchor),
format!(r#" name="{}""#, anchor), format!(r#" name="{}""#, anchor),
format!(r#" NAME="{}""#, anchor),
]; ];
if checks.iter().any(|check| body[..].contains(&check[..])) { if checks.iter().any(|check| body[..].contains(&check[..])) {
@ -272,6 +276,15 @@ mod tests {
assert!(res.is_ok()); assert!(res.is_ok());
} }
// https://github.com/getzola/zola/issues/948
#[test]
fn can_validate_anchors_in_capital() {
let url = "https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect";
let body = r#"<body><h3 ID="method.collect">collect</h3></body>"#.to_string();
let res = check_page_for_anchor(url, body);
assert!(res.is_ok());
}
#[test] #[test]
fn can_validate_anchors_with_other_quotes() { fn can_validate_anchors_with_other_quotes() {
let url = "https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect"; let url = "https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect";