From c434098fb17820e4a80956f7fcb44f5c96f0eea4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 3 Oct 2024 04:41:13 +0000 Subject: [PATCH] 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 --- crates/ruma-identifiers-validation/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/ruma-identifiers-validation/src/lib.rs b/crates/ruma-identifiers-validation/src/lib.rs index d62234c9..b83a66aa 100644 --- a/crates/ruma-identifiers-validation/src/lib.rs +++ b/crates/ruma-identifiers-validation/src/lib.rs @@ -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.