Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tu6ge committed Aug 29, 2024
1 parent 520f5d5 commit 912d3aa
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/rule/available/email/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,21 @@ impl<'a> Cursor<'a> {

return Some(EmailToken::Ip);
}
c => {
return if !c.is_ascii() {
let domain = &self.email_str[self.at_index + 1..];
idna::domain_to_ascii(domain).ok().map(|d| {
// https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.3.1.1
if d.chars().count() > 255 {
return EmailToken::IllegalChar;
}
self.is_idna_domain = true;
EmailToken::IdnaDomain
})
} else {
// other ascii characters
self.token.push(EmailToken::IllegalChar);
return Some(EmailToken::IllegalChar);
};
c if !c.is_ascii() => {
let domain = &self.email_str[self.at_index + 1..];
idna::domain_to_ascii(domain).ok().map(|d| {
// https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.3.1.1
if d.chars().count() > 255 {
return EmailToken::IllegalChar;
}
self.is_idna_domain = true;
EmailToken::IdnaDomain
})
}
_ => {
// other ascii characters
self.token.push(EmailToken::IllegalChar);
Some(EmailToken::IllegalChar)
}
}
}
Expand Down

0 comments on commit 912d3aa

Please sign in to comment.