From 91bf91a88b30ef1cf3e17579cad0de60e0298bb8 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 25 Mar 2020 19:54:22 +0100 Subject: [PATCH] Fix link checker not checking for capital id/name Closes #948 --- CHANGELOG.md | 4 ++++ components/link_checker/src/lib.rs | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f59486f..136edd38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.10.2 (unreleased) + +- Fix link checker not looking for anchor with capital id/name + ## 0.10.1 (2020-03-12) - Set user agent for HTTP requests diff --git a/components/link_checker/src/lib.rs b/components/link_checker/src/lib.rs index e9b038bc..7ecd6ca8 100644 --- a/components/link_checker/src/lib.rs +++ b/components/link_checker/src/lib.rs @@ -118,11 +118,15 @@ fn has_anchor(url: &str) -> bool { fn check_page_for_anchor(url: &str, body: String) -> Result<()> { let index = url.find('#').unwrap(); let anchor = url.get(index + 1..).unwrap(); - let checks: [String; 4] = [ + let checks: [String; 8] = [ format!(" id='{}'", anchor), + format!(" ID='{}'", anchor), format!(r#" id="{}""#, anchor), + format!(r#" ID="{}""#, anchor), format!(" name='{}'", anchor), + format!(" NAME='{}'", anchor), format!(r#" name="{}""#, anchor), + format!(r#" NAME="{}""#, anchor), ]; if checks.iter().any(|check| body[..].contains(&check[..])) { @@ -272,6 +276,15 @@ mod tests { 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#"

collect

"#.to_string(); + let res = check_page_for_anchor(url, body); + assert!(res.is_ok()); + } + #[test] fn can_validate_anchors_with_other_quotes() { let url = "https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect";