Support anchors without quotes in link checker (#1118)

* Support anchors without quotes in link checker

Not widely used but in many cases quotes in attributes are optional.

* Fix duplicate test
This commit is contained in:
Tuomas Siipola 2020-08-07 18:02:02 +03:00 committed by GitHub
parent b04be90326
commit 4a3c1568a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -101,11 +101,15 @@ fn has_anchor(url: &str) -> bool {
fn check_page_for_anchor(url: &str, body: String) -> errors::Result<()> {
let index = url.find('#').unwrap();
let anchor = url.get(index + 1..).unwrap();
let checks: [String; 8] = [
let checks = [
format!(" id={}", anchor),
format!(" ID={}", anchor),
format!(" id='{}'", anchor),
format!(" ID='{}'", anchor),
format!(r#" id="{}""#, anchor),
format!(r#" ID="{}""#, anchor),
format!(" name={}", anchor),
format!(" NAME={}", anchor),
format!(" name='{}'", anchor),
format!(" NAME='{}'", anchor),
format!(r#" name="{}""#, anchor),
@ -256,7 +260,7 @@ mod tests {
}
#[test]
fn can_validate_anchors() {
fn can_validate_anchors_with_double_quotes() {
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);
@ -273,9 +277,17 @@ mod tests {
}
#[test]
fn can_validate_anchors_with_other_quotes() {
fn can_validate_anchors_with_single_quotes() {
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 body = "<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_without_quotes() {
let url = "https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect";
let body = "<body><h3 id=method.collect>collect</h3></body>".to_string();
let res = check_page_for_anchor(url, body);
assert!(res.is_ok());
}