From f51b2741d3202b4fa83c5b05245a3b3b12822072 Mon Sep 17 00:00:00 2001 From: EAimTY Date: Sat, 3 Jun 2023 22:13:10 +0900 Subject: [PATCH] split server hostname and port using the last `:` --- tuic-client/src/config.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tuic-client/src/config.rs b/tuic-client/src/config.rs index 8178b47..70feb0a 100644 --- a/tuic-client/src/config.rs +++ b/tuic-client/src/config.rs @@ -245,16 +245,16 @@ pub fn deserialize_server<'de, D>(deserializer: D) -> Result<(String, u16), D::E where D: Deserializer<'de>, { - let s = String::deserialize(deserializer)?; - let mut parts = s.split(':'); + let mut s = String::deserialize(deserializer)?; - match (parts.next(), parts.next(), parts.next()) { - (Some(domain), Some(port), None) => port.parse().map_or_else( - |e| Err(DeError::custom(e)), - |port| Ok((domain.to_owned(), port)), - ), - _ => Err(DeError::custom("invalid server address")), - } + let (domain, port) = s + .rsplit_once(':') + .ok_or(DeError::custom("invalid server address"))?; + + let port = port.parse().map_err(DeError::custom)?; + s.truncate(domain.len()); + + Ok((s, port)) } pub fn deserialize_password<'de, D>(deserializer: D) -> Result, D::Error>