From acb02f96bcfb9c78818fbb534dec54d28a999de0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 17 Apr 2020 14:53:45 +0200 Subject: [PATCH] Update parse_with_server_name's id bounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … from `Into>` to `AsRef + Into` --- src/user_id.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/user_id.rs b/src/user_id.rs index e504e47d..26519b61 100644 --- a/src/user_id.rs +++ b/src/user_id.rs @@ -63,22 +63,23 @@ impl UserId { /// user ID or just the localpart. It only supports a valid user ID or a valid user ID /// localpart, not the localpart plus the `@` prefix, or the localpart plus server name without /// the `@` prefix. - pub fn parse_with_server_name<'a>( - id: impl Into>, + pub fn parse_with_server_name( + id: impl AsRef + Into, server_name: &str, ) -> Result { - let id = id.into(); - if id.starts_with('@') { - Self::try_from(id) + let id_str = id.as_ref(); + + if id_str.starts_with('@') { + Self::try_from(id.into()) } else { - let is_fully_conforming = localpart_is_fully_comforming(&id)?; + let is_fully_conforming = localpart_is_fully_comforming(id_str)?; if !is_valid_server_name(server_name) { return Err(Error::InvalidServerName); } Ok(Self { - full_id: format!("@{}:{}", id, server_name), - colon_idx: NonZeroU8::new(id.len() as u8 + 1).unwrap(), + full_id: format!("@{}:{}", id_str, server_name), + colon_idx: NonZeroU8::new(id_str.len() as u8 + 1).unwrap(), is_historical: !is_fully_conforming, }) }