diff --git a/url/src/lib.rs b/url/src/lib.rs index ad3c89001..3aa9f4873 100644 --- a/url/src/lib.rs +++ b/url/src/lib.rs @@ -2088,6 +2088,9 @@ impl Url { pub fn set_password(&mut self, password: Option<&str>) -> Result<(), ()> { // has_host implies !cannot_be_a_base if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" { + if password.is_none() || password == Some("") { + return Ok(()); + } return Err(()); } let password = password.unwrap_or_default(); @@ -2182,6 +2185,9 @@ impl Url { pub fn set_username(&mut self, username: &str) -> Result<(), ()> { // has_host implies !cannot_be_a_base if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" { + if username.is_empty() { + return Ok(()); + } return Err(()); } let username_start = self.scheme_end + 3;