Skip to content

Commit

Permalink
Rollup merge of rust-lang#34566 - ollie27:linkchecker_invalid_urls, r…
Browse files Browse the repository at this point in the history
…=alexcrichton

Reject invalid urls in linkchecker

For example root-relative links will now be rejected.

Also remove some exceptions which have since been fixed and fix a typo in
the broken redirect handling.
  • Loading branch information
Manishearth authored Jul 2, 2016
2 parents 76705df + 01386e6 commit 533ce9a
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/tools/linkchecker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,6 @@ fn check(cache: &mut Cache,
return None;
}

if file.ends_with("std/sys/ext/index.html") {
return None;
}

if let Some(file) = file.to_str() {
// FIXME(#31948)
if file.contains("ParseFloatError") {
return None;
}
// weird reexports, but this module is on its way out, so chalk it up to
// "rustdoc weirdness" and move on from there
if file.contains("scoped_tls") {
return None;
}
}

let mut parser = UrlParser::new();
parser.base_url(base);

Expand All @@ -170,12 +154,24 @@ fn check(cache: &mut Cache,

// Search for anything that's the regex 'href[ ]*=[ ]*".*?"'
with_attrs_in_source(&contents, " href", |url, i| {
// Ignore external URLs
if url.starts_with("http:") || url.starts_with("https:") ||
url.starts_with("javascript:") || url.starts_with("ftp:") ||
url.starts_with("irc:") || url.starts_with("data:") {
return;
}
// Once we've plucked out the URL, parse it using our base url and
// then try to extract a file path. If either of these fail then we
// just keep going.
// then try to extract a file path.
let (parsed_url, path) = match url_to_file_path(&parser, url) {
Some((url, path)) => (url, PathBuf::from(path)),
None => return,
None => {
*errors = true;
println!("{}:{}: invalid link - {}",
pretty_file.display(),
i + 1,
url);
return;
}
};

// Alright, if we've found a file name then this file had better
Expand All @@ -197,10 +193,11 @@ fn check(cache: &mut Cache,
Ok(res) => res,
Err(LoadError::IOError(err)) => panic!(format!("{}", err)),
Err(LoadError::BrokenRedirect(target, _)) => {
print!("{}:{}: broken redirect to {}",
pretty_file.display(),
i + 1,
target.display());
*errors = true;
println!("{}:{}: broken redirect to {}",
pretty_file.display(),
i + 1,
target.display());
return;
}
Err(LoadError::IsRedirect) => unreachable!(),
Expand Down

0 comments on commit 533ce9a

Please sign in to comment.