diff --git a/crates/nu-command/src/network/url/join.rs b/crates/nu-command/src/network/url/join.rs index 1d4b5bc8b9..2a93d33578 100644 --- a/crates/nu-command/src/network/url/join.rs +++ b/crates/nu-command/src/network/url/join.rs @@ -317,13 +317,11 @@ impl UrlComponents { } pub fn to_url(&self, span: Span) -> Result { - let mut user_and_pwd: String = String::from(""); - - if let Some(usr) = &self.username { - if let Some(pwd) = &self.password { - user_and_pwd = format!("{usr}:{pwd}@"); - } - } + let user_and_pwd = match (&self.username, &self.password) { + (Some(usr), Some(pwd)) => format!("{usr}:{pwd}@"), + (Some(usr), None) => format!("{usr}@"), + _ => String::from(""), + }; let scheme_result = match &self.scheme { Some(s) => Ok(s), diff --git a/crates/nu-command/tests/commands/url/join.rs b/crates/nu-command/tests/commands/url/join.rs index 9fa5ab16fc..bafe7881f4 100644 --- a/crates/nu-command/tests/commands/url/join.rs +++ b/crates/nu-command/tests/commands/url/join.rs @@ -31,7 +31,7 @@ fn url_join_with_only_user() { "# )); - assert_eq!(actual.out, "http://localhost"); + assert_eq!(actual.out, "http://usr@localhost"); } #[test]