Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #844 by returning Ok(()) if the port, username or password is empty #845

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,9 @@ impl Url {
pub fn set_port(&mut self, mut port: Option<u16>) -> Result<(), ()> {
// has_host implies !cannot_be_a_base
if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" {
if port.is_none() {
return Ok(());
}
return Err(());
}
if port.is_some() && port == parser::default_port(self.scheme()) {
Expand Down Expand Up @@ -2088,6 +2091,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();
Expand Down Expand Up @@ -2182,6 +2188,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;
Expand Down