Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject invalid urls in linkchecker #34566

Merged
merged 1 commit into from
Jul 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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