mirror of
https://github.com/mailscope/kumomta.git
synced 2026-10-30 01:56:52 +00:00
rfc5321: improve error message for bad IDNA domains
Previously, we'd use the default presentation for the Error type reported by the idna crate. Unfortunately, that type holds no context: it is a zero-sized empty struct type, and it chooses to render itself as `Errors`, which isn't super helpful, but it is hard to convey every possible error clause from the underlying spec, so I understand why this is this way. This commit handles that error case to present a slightly more informative error message. It doesn't provide context on what specifically is bad about the input, but it at least helps to characterize that the domain is bad, rather than imply that we don't know how to deal with punycode at all. The specific problem with the domain in the included test case is most likely BIDI related per discussion in https://github.com/servo/rust-url/issues/489
This commit is contained in:
@@ -355,7 +355,7 @@ impl Domain {
|
||||
pub fn name(name: &str) -> Result<Self, String> {
|
||||
match idna::domain_to_ascii(name) {
|
||||
Ok(name) => Ok(Self::Name(name)),
|
||||
Err(err) => Err(format!("{err:#}")),
|
||||
Err(_empty_error_type) => Err(format!("invalid IDNA domain {name}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -588,6 +588,16 @@ mod test {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_rcpt_to_punycode() {
|
||||
assert_eq!(
|
||||
Parser::parse_command("Rcpt To:<user@4bed.xn--5dbhlacyps5bf4a.com>")
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"invalid IDNA domain 4bed.xn--5dbhlacyps5bf4a.com"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_rcpt_to() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user