From 7859b69e92e8910360643b12ae89993de66eeefd Mon Sep 17 00:00:00 2001 From: Chance Date: Sun, 2 Jul 2023 11:32:55 -0400 Subject: [PATCH] Resolves #844 by returning `Ok(())` if username or password is empty --- url/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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;