Skip to content

Commit 34199a4

Browse files
Rejected urls (#1990)
* add test_check_data_uris * Update lychee-bin/tests/data_uris.rs Co-authored-by: Thomas Zahner <thomas.zahner@protonmail.ch> * fmt * Convert InvalidUrlHost into Unsupported status * Inline conversion from reqwest::Error into Status --------- Co-authored-by: rina <k@rina.fyi> Co-authored-by: katrinafyi <39479354+katrinafyi@users.noreply.github.com>
1 parent f48fcc9 commit 34199a4

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

lychee-bin/tests/data_uris.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,16 @@ mod cli {
5353
let output = std::str::from_utf8(&output.stdout).unwrap();
5454
assert_eq!(output.lines().count(), 5);
5555
}
56+
57+
#[test]
58+
fn test_check_data_uris() {
59+
let input = fixtures_path().join("TEST_DATA_URIS.html");
60+
61+
cargo_bin_cmd!()
62+
.arg(input)
63+
.arg("--exclude-loopback")
64+
.assert()
65+
.success()
66+
.stdout(contains("3 Unsupported"));
67+
}
5668
}

lychee-lib/src/checker/website.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ impl WebsiteChecker {
158158
status
159159
}
160160
}
161-
Err(e) => match e {
162-
ErrorKind::NetworkRequest(error) => Status::from(error),
163-
_ => e.into(),
164-
},
161+
Err(e) => e.into(),
165162
}
166163
}
167164

lychee-lib/src/types/status.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,22 @@ impl Status {
296296

297297
impl From<ErrorKind> for Status {
298298
fn from(e: ErrorKind) -> Self {
299-
Self::Error(e)
300-
}
301-
}
302-
303-
impl From<reqwest::Error> for Status {
304-
fn from(e: reqwest::Error) -> Self {
305-
if e.is_timeout() {
306-
Self::Timeout(e.status())
307-
} else if e.is_builder() {
308-
Self::Unsupported(ErrorKind::BuildRequestClient(e))
309-
} else if e.is_body() || e.is_decode() {
310-
Self::Unsupported(ErrorKind::ReadResponseBody(e))
311-
} else {
312-
Self::Error(ErrorKind::NetworkRequest(e))
299+
match e {
300+
ErrorKind::InvalidUrlHost => Status::Unsupported(ErrorKind::InvalidUrlHost),
301+
ErrorKind::NetworkRequest(e)
302+
| ErrorKind::ReadResponseBody(e)
303+
| ErrorKind::BuildRequestClient(e) => {
304+
if e.is_timeout() {
305+
Self::Timeout(e.status())
306+
} else if e.is_builder() {
307+
Self::Unsupported(ErrorKind::BuildRequestClient(e))
308+
} else if e.is_body() || e.is_decode() {
309+
Self::Unsupported(ErrorKind::ReadResponseBody(e))
310+
} else {
311+
Self::Error(ErrorKind::NetworkRequest(e))
312+
}
313+
}
314+
e => Self::Error(e),
313315
}
314316
}
315317
}

0 commit comments

Comments
 (0)