Skip to content

Commit 01386e6

Browse files
committed
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.
1 parent 126af08 commit 01386e6

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/tools/linkchecker/main.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,6 @@ fn check(cache: &mut Cache,
138138
return None;
139139
}
140140

141-
if file.ends_with("std/sys/ext/index.html") {
142-
return None;
143-
}
144-
145-
if let Some(file) = file.to_str() {
146-
// FIXME(#31948)
147-
if file.contains("ParseFloatError") {
148-
return None;
149-
}
150-
// weird reexports, but this module is on its way out, so chalk it up to
151-
// "rustdoc weirdness" and move on from there
152-
if file.contains("scoped_tls") {
153-
return None;
154-
}
155-
}
156-
157141
let mut parser = UrlParser::new();
158142
parser.base_url(base);
159143

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

171155
// Search for anything that's the regex 'href[ ]*=[ ]*".*?"'
172156
with_attrs_in_source(&contents, " href", |url, i| {
157+
// Ignore external URLs
158+
if url.starts_with("http:") || url.starts_with("https:") ||
159+
url.starts_with("javascript:") || url.starts_with("ftp:") ||
160+
url.starts_with("irc:") || url.starts_with("data:") {
161+
return;
162+
}
173163
// Once we've plucked out the URL, parse it using our base url and
174-
// then try to extract a file path. If either of these fail then we
175-
// just keep going.
164+
// then try to extract a file path.
176165
let (parsed_url, path) = match url_to_file_path(&parser, url) {
177166
Some((url, path)) => (url, PathBuf::from(path)),
178-
None => return,
167+
None => {
168+
*errors = true;
169+
println!("{}:{}: invalid link - {}",
170+
pretty_file.display(),
171+
i + 1,
172+
url);
173+
return;
174+
}
179175
};
180176

181177
// Alright, if we've found a file name then this file had better
@@ -197,10 +193,11 @@ fn check(cache: &mut Cache,
197193
Ok(res) => res,
198194
Err(LoadError::IOError(err)) => panic!(format!("{}", err)),
199195
Err(LoadError::BrokenRedirect(target, _)) => {
200-
print!("{}:{}: broken redirect to {}",
201-
pretty_file.display(),
202-
i + 1,
203-
target.display());
196+
*errors = true;
197+
println!("{}:{}: broken redirect to {}",
198+
pretty_file.display(),
199+
i + 1,
200+
target.display());
204201
return;
205202
}
206203
Err(LoadError::IsRedirect) => unreachable!(),

0 commit comments

Comments
 (0)