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:
parent
b04be90326
commit
4a3c1568a2
|
@ -101,11 +101,15 @@ fn has_anchor(url: &str) -> bool {
|
||||||
fn check_page_for_anchor(url: &str, body: String) -> errors::Result<()> {
|
fn check_page_for_anchor(url: &str, body: String) -> errors::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; 8] = [
|
let checks = [
|
||||||
|
format!(" id={}", anchor),
|
||||||
|
format!(" ID={}", anchor),
|
||||||
format!(" id='{}'", anchor),
|
format!(" id='{}'", anchor),
|
||||||
format!(" ID='{}'", anchor),
|
format!(" ID='{}'", anchor),
|
||||||
format!(r#" id="{}""#, anchor),
|
format!(r#" id="{}""#, anchor),
|
||||||
format!(r#" ID="{}""#, anchor),
|
format!(r#" ID="{}""#, anchor),
|
||||||
|
format!(" name={}", anchor),
|
||||||
|
format!(" NAME={}", anchor),
|
||||||
format!(" name='{}'", anchor),
|
format!(" name='{}'", anchor),
|
||||||
format!(" NAME='{}'", anchor),
|
format!(" NAME='{}'", anchor),
|
||||||
format!(r#" name="{}""#, anchor),
|
format!(r#" name="{}""#, anchor),
|
||||||
|
@ -256,7 +260,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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 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 = r#"<body><h3 id="method.collect">collect</h3></body>"#.to_string();
|
||||||
let res = check_page_for_anchor(url, body);
|
let res = check_page_for_anchor(url, body);
|
||||||
|
@ -273,9 +277,17 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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 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);
|
let res = check_page_for_anchor(url, body);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue