Skip to content

Commit

Permalink
Fix link checker not checking for capital id/name
Browse files Browse the repository at this point in the history
Closes #948
  • Loading branch information
Keats committed Mar 25, 2020
1 parent 30f6f38 commit 91bf91a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 14 additions & 1 deletion components/link_checker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..])) {
Expand Down Expand Up @@ -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#"<body><h3 ID="method.collect">collect</h3></body>"#.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";
Expand Down

1 comment on commit 91bf91a

@phil-opp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Please sign in to comment.