Skip to content

Commit 76fa56d

Browse files
authored
Merge pull request #200 from lycheeverse/exclude-mail-fix
Fix exclude mail, add tests
2 parents bcb3933 + 2b044a6 commit 76fa56d

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

fixtures/TEST_EMAIL.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
https://endler.dev
2+
test@example.org
3+
foo@bar.dev
4+
https://example.org
5+
octocat+github@github.com
6+
mailto:test2@example.org

src/bin/lychee/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ async fn run(cfg: &Config, inputs: Vec<Input>) -> Result<i32> {
107107
.exclude_private_ips(cfg.exclude_private)
108108
.exclude_link_local_ips(cfg.exclude_link_local)
109109
.exclude_loopback_ips(cfg.exclude_loopback)
110+
.exclude_mail(cfg.exclude_mail)
110111
.max_redirects(cfg.max_redirects)
111112
.user_agent(cfg.user_agent.clone())
112113
.allow_insecure(cfg.insecure)

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl ClientBuilder {
9595
private_ips: enable_exclude(self.exclude_private_ips.unwrap_or_default()),
9696
link_local_ips: enable_exclude(self.exclude_link_local_ips.unwrap_or_default()),
9797
loopback_ips: enable_exclude(self.exclude_loopback_ips.unwrap_or_default()),
98-
mail: enable_exclude(self.exclude_mail.unwrap_or_default()),
98+
mail: self.exclude_mail.unwrap_or_default(),
9999
}
100100
}
101101

src/filter/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ mod test {
188188
assert_eq!(filter.excluded(&request("https://example.org")), true);
189189
}
190190

191+
#[test]
192+
fn test_exclude_mail() {
193+
let excludes = Excludes {
194+
mail: true,
195+
..Default::default()
196+
};
197+
let filter = Filter::new(None, Some(excludes), None);
198+
199+
assert_eq!(
200+
filter.excluded(&Request::new(
201+
Uri::Mail("mail@example.org".to_string()),
202+
Input::Stdin,
203+
)),
204+
true
205+
);
206+
assert_eq!(
207+
filter.excluded(&Request::new(
208+
Uri::Mail("foo@bar.dev".to_string()),
209+
Input::Stdin,
210+
)),
211+
true
212+
);
213+
assert_eq!(filter.excluded(&request("http://bar.dev")), false);
214+
}
215+
191216
#[test]
192217
fn test_exclude_regex() {
193218
let excludes = Excludes {

tests/cli.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ mod cli {
3636
.stdout(contains("Errors...........0"));
3737
}
3838

39+
#[test]
40+
fn test_exclude_email() {
41+
let mut cmd = main_command();
42+
43+
let test_path = fixtures_path().join("TEST_EMAIL.md");
44+
45+
// assert that the command runs OK, and that it excluded all the links
46+
cmd.arg("--exclude-mail")
47+
.arg(test_path)
48+
.assert()
49+
.success()
50+
.stdout(contains("Total............6"))
51+
.stdout(contains("Excluded.........4"))
52+
.stdout(contains("Successful.......2"))
53+
.stdout(contains("Errors...........0"));
54+
}
55+
3956
/// Test that a GitHub link can be checked without specifying the token.
4057
#[test]
4158
fn test_check_github_no_token() {

0 commit comments

Comments
 (0)