mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-22 05:54:46 +00:00
Don't check example mail addresses by default (#815)
This was an oversight so far that became apparent after our recent fix for email addreses with query params (e.g. `test@example.com?subject=test`). The parsing of email addresses has improved and so we detect more mail addresses, but we didn't check if they belonged to an example domain, causing false-positive checks.
This commit is contained in:
parent
287624691b
commit
765f7adb12
4 changed files with 26 additions and 2 deletions
6
fixtures/TEST_EXAMPLE_DOMAINS.md
vendored
6
fixtures/TEST_EXAMPLE_DOMAINS.md
vendored
|
|
@ -1,7 +1,13 @@
|
|||
http://example.com
|
||||
https://github.com/rust-lang/rust
|
||||
https://example.com
|
||||
hi@example.edu
|
||||
http://example.org
|
||||
https://www.rust-lang.org/
|
||||
test@foo.example.org
|
||||
http://foo.example.org
|
||||
mailto:foo@bar.dev
|
||||
mailto:hello@example.com?subject=hello
|
||||
http://example.net/foo/bar
|
||||
mail@example.com
|
||||
mail@somedomain.com
|
||||
|
|
|
|||
|
|
@ -35,12 +35,14 @@ mod cli {
|
|||
.arg("--dump")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(contains("mail@somedomain.com"))
|
||||
.stdout(contains("foo@bar.dev"))
|
||||
.stdout(contains("https://github.com/rust-lang/rust"))
|
||||
.stdout(contains("https://www.rust-lang.org/"));
|
||||
|
||||
let output = cmd.get_output();
|
||||
let output = std::str::from_utf8(&output.stdout).unwrap();
|
||||
assert_eq!(output.lines().count(), 2);
|
||||
assert_eq!(output.lines().count(), 4);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,16 @@ pub fn is_example_domain(uri: &Uri) -> bool {
|
|||
// `foo.example.com`
|
||||
EXAMPLE_DOMAINS.iter().any(|tld| domain.ends_with(tld))
|
||||
}
|
||||
None => false,
|
||||
None => {
|
||||
// Check if the URI is an email address.
|
||||
// e.g. `mailto:mail@example.com`
|
||||
// In this case, the domain is part of the path
|
||||
if uri.is_mail() {
|
||||
EXAMPLE_DOMAINS.iter().any(|tld| uri.path().ends_with(tld))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
};
|
||||
res
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,13 @@ impl Uri {
|
|||
self.url.domain()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
/// Returns the path of the URI (e.g. `/path/to/resource`)
|
||||
pub fn path(&self) -> &str {
|
||||
self.url.path()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
/// Unless this URL is cannot-be-a-base,
|
||||
|
|
|
|||
Loading…
Reference in a new issue