From b4ff992073d1088b79a4e3f5d425cb93fc057eb8 Mon Sep 17 00:00:00 2001 From: Chance Date: Sun, 2 Jul 2023 11:37:42 -0400 Subject: [PATCH 1/3] 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; From 99a74880595dc5a4ca058cfa65e76c088d9afc21 Mon Sep 17 00:00:00 2001 From: Chance Date: Fri, 4 Aug 2023 11:21:26 -0400 Subject: [PATCH 2/3] applies the same value check to set_port --- url/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/url/src/lib.rs b/url/src/lib.rs index 3aa9f4873..9b20df417 100644 --- a/url/src/lib.rs +++ b/url/src/lib.rs @@ -1770,6 +1770,9 @@ impl Url { pub fn set_port(&mut self, mut port: Option) -> Result<(), ()> { // has_host implies !cannot_be_a_base if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" { + if port.is_some() { + return Ok(()); + } return Err(()); } if port.is_some() && port == parser::default_port(self.scheme()) { From 941dade47a3036c251b37bdaaa4af29086ec4124 Mon Sep 17 00:00:00 2001 From: Chance Date: Fri, 4 Aug 2023 11:24:11 -0400 Subject: [PATCH 3/3] fixes set_port --- url/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/url/src/lib.rs b/url/src/lib.rs index 9b20df417..3d6326c7d 100644 --- a/url/src/lib.rs +++ b/url/src/lib.rs @@ -1770,7 +1770,7 @@ impl Url { pub fn set_port(&mut self, mut port: Option) -> Result<(), ()> { // has_host implies !cannot_be_a_base if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" { - if port.is_some() { + if port.is_none() { return Ok(()); } return Err(());