Improve validation error for empty mxid.
Previously an empty MXID was reported as MissingLeadingSigil but a more concise variant is just Empty. Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
b57e03e342
commit
c434098fb1
@ -22,17 +22,17 @@ pub use error::Error;
|
||||
const MAX_BYTES: usize = 255;
|
||||
|
||||
/// Checks if an identifier is valid.
|
||||
fn validate_id(id: &str, first_byte: u8) -> Result<(), Error> {
|
||||
fn validate_id(id: &str, sigil: u8) -> Result<(), Error> {
|
||||
#[cfg(not(feature = "compat-arbitrary-length-ids"))]
|
||||
if id.len() > MAX_BYTES {
|
||||
return Err(Error::MaximumLengthExceeded);
|
||||
}
|
||||
|
||||
if id.as_bytes().first() != Some(&first_byte) {
|
||||
return Err(Error::MissingLeadingSigil);
|
||||
match id.as_bytes().first() {
|
||||
Some(&first_byte) if first_byte == sigil => Ok(()),
|
||||
Some(_) => Err(Error::MissingLeadingSigil),
|
||||
None => Err(Error::Empty),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks an identifier that contains a localpart and hostname for validity.
|
||||
|
Loading…
x
Reference in New Issue
Block a user