Error on invalid localpart

This commit is contained in:
Jonas Platte 2020-04-17 12:19:41 +02:00
parent e8f7bd9f6d
commit ad48d3972e
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -81,14 +81,15 @@ fn parse_id(id: &str, valid_sigils: &[char]) -> Result<NonZeroU8, Error> {
validate_id(id, valid_sigils)?;
let colon_idx = id.find(':').ok_or(Error::MissingDelimiter)?;
if colon_idx < 2 {
return Err(Error::InvalidLocalPart);
}
if !is_valid_server_name(&id[colon_idx + 1..]) {
return Err(Error::InvalidServerName);
}
match NonZeroU8::new(colon_idx as u8) {
Some(idx) => Ok(idx),
None => Err(Error::InvalidLocalPart),
}
Ok(NonZeroU8::new(colon_idx as u8).unwrap())
}
/// Deserializes any type of id using the provided TryFrom implementation.