diff --git a/crates/nu-command/src/network/url/join.rs b/crates/nu-command/src/network/url/join.rs index 8e1a745499..46ecc740c2 100644 --- a/crates/nu-command/src/network/url/join.rs +++ b/crates/nu-command/src/network/url/join.rs @@ -191,7 +191,11 @@ impl UrlComponents { .collect::, ShellError>>()? .join("&"); - qs = format!("?{qs}"); + qs = if !qs.trim().is_empty() { + format!("?{qs}") + } else { + qs + }; if let Some(q) = self.query { if q != qs { diff --git a/crates/nu-command/tests/commands/url/join.rs b/crates/nu-command/tests/commands/url/join.rs index cd10916ffb..5198228f0e 100644 --- a/crates/nu-command/tests/commands/url/join.rs +++ b/crates/nu-command/tests/commands/url/join.rs @@ -366,3 +366,21 @@ fn url_join_with_fragment_and_params() { "http://usr:pwd@localhost:1234?par_1=aaa&par_2=bbb#frag" ); } + +#[test] +fn url_join_with_empty_params() { + let actual = nu!( + cwd: ".", pipeline( + r#" + { + "scheme": "https", + "host": "localhost", + "path": "/foo", + "params": {} + } | url join + "# + ) + ); + + assert_eq!(actual.out, "https://localhost/foo"); +}