Skip to content

Commit f0bab98

Browse files
authored
Auto merge of #35638 - ahmedcharles:url, r=alexcrichton
Upgrade linkchecker to url 1.2.0.
2 parents 47e6da2 + d56a5b9 commit f0bab98

File tree

3 files changed

+20
-45
lines changed

3 files changed

+20
-45
lines changed

src/tools/linkchecker/Cargo.lock

+10-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/linkchecker/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
authors = ["Alex Crichton <alex@alexcrichton.com>"]
55

66
[dependencies]
7-
url = "0.5"
7+
url = "1.2"
88

99
[[bin]]
1010
name = "linkchecker"

src/tools/linkchecker/main.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::path::{Path, PathBuf};
3333
use std::collections::{HashMap, HashSet};
3434
use std::collections::hash_map::Entry;
3535

36-
use url::{Url, UrlParser};
36+
use url::Url;
3737

3838
use Redirect::*;
3939

@@ -92,7 +92,7 @@ fn walk(cache: &mut Cache, root: &Path, dir: &Path, url: &mut Url, errors: &mut
9292
for entry in t!(dir.read_dir()).map(|e| t!(e)) {
9393
let path = entry.path();
9494
let kind = t!(entry.file_type());
95-
url.path_mut().unwrap().push(entry.file_name().into_string().unwrap());
95+
url.path_segments_mut().unwrap().push(entry.file_name().to_str().unwrap());
9696
if kind.is_dir() {
9797
walk(cache, root, &path, url, errors);
9898
} else {
@@ -104,7 +104,7 @@ fn walk(cache: &mut Cache, root: &Path, dir: &Path, url: &mut Url, errors: &mut
104104
entry.source = String::new();
105105
}
106106
}
107-
url.path_mut().unwrap().pop();
107+
url.path_segments_mut().unwrap().pop();
108108
}
109109
}
110110

@@ -138,9 +138,6 @@ fn check(cache: &mut Cache,
138138
return None;
139139
}
140140

141-
let mut parser = UrlParser::new();
142-
parser.base_url(base);
143-
144141
let res = load_file(cache, root, PathBuf::from(file), SkipRedirect);
145142
let (pretty_file, contents) = match res {
146143
Ok(res) => res,
@@ -162,7 +159,7 @@ fn check(cache: &mut Cache,
162159
}
163160
// Once we've plucked out the URL, parse it using our base url and
164161
// then try to extract a file path.
165-
let (parsed_url, path) = match url_to_file_path(&parser, url) {
162+
let (parsed_url, path) = match url_to_file_path(&base, url) {
166163
Some((url, path)) => (url, PathBuf::from(path)),
167164
None => {
168165
*errors = true;
@@ -203,7 +200,7 @@ fn check(cache: &mut Cache,
203200
Err(LoadError::IsRedirect) => unreachable!(),
204201
};
205202

206-
if let Some(ref fragment) = parsed_url.fragment {
203+
if let Some(ref fragment) = parsed_url.fragment() {
207204
// Fragments like `#1-6` are most likely line numbers to be
208205
// interpreted by javascript, so we're ignoring these
209206
if fragment.splitn(2, '-')
@@ -214,7 +211,7 @@ fn check(cache: &mut Cache,
214211
let entry = &mut cache.get_mut(&pretty_path).unwrap();
215212
entry.parse_ids(&pretty_path, &contents, errors);
216213

217-
if !entry.ids.contains(fragment) {
214+
if !entry.ids.contains(*fragment) {
218215
*errors = true;
219216
print!("{}:{}: broken link fragment ",
220217
pretty_file.display(),
@@ -271,10 +268,8 @@ fn load_file(cache: &mut Cache,
271268
}
272269
};
273270
let base = Url::from_file_path(&file).unwrap();
274-
let mut parser = UrlParser::new();
275-
parser.base_url(&base);
276271

277-
match maybe_redirect.and_then(|url| url_to_file_path(&parser, &url)) {
272+
match maybe_redirect.and_then(|url| url_to_file_path(&base, &url)) {
278273
Some((_, redirect_file)) => {
279274
let path = PathBuf::from(redirect_file);
280275
load_file(cache, root, path, FromRedirect(true))
@@ -299,8 +294,8 @@ fn maybe_redirect(source: &str) -> Option<String> {
299294
})
300295
}
301296

302-
fn url_to_file_path(parser: &UrlParser, url: &str) -> Option<(Url, PathBuf)> {
303-
parser.parse(url)
297+
fn url_to_file_path(parser: &Url, url: &str) -> Option<(Url, PathBuf)> {
298+
parser.join(url)
304299
.ok()
305300
.and_then(|parsed_url| parsed_url.to_file_path().ok().map(|f| (parsed_url, f)))
306301
}

0 commit comments

Comments
 (0)