forked from extern/nushell
add table params support to url join
and url build-query
(#14239)
Add `table<key, value>` support to `url join` for the `params` field, and as input to `url build-query` #14162 # Description ```nushell { "scheme": "http", "username": "usr", "password": "pwd", "host": "localhost", "params": [ ["key", "value"]; ["par_1", "aaa"], ["par_2", "bbb"], ["par_1", "ccc"], ["par_2", "ddd"], ], "port": "1234", } | url join ``` ``` http://usr:pwd@localhost:1234?par_1=aaa&par_2=bbb&par_1=ccc&par_2=ddd ``` --- ```nushell [ ["key", "value"]; ["par_1", "aaa"], ["par_2", "bbb"], ["par_1", "ccc"], ["par_2", "ddd"], ] | url build-query ``` ``` par_1=aaa&par_2=bbb&par_1=ccc&par_2=ddd ``` # User-Facing Changes ## `url build-query` - can no longer accept one row table input as if it were a record --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
@ -156,7 +156,7 @@ fn url_join_with_different_query_and_params() {
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Mismatch, qs from params is: ?par_1=aaab&par_2=bbb"));
|
||||
.contains("Mismatch, query string from params is: ?par_1=aaab&par_2=bbb"));
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("instead query is: ?par_1=aaa&par_2=bbb"));
|
||||
@ -183,7 +183,7 @@ fn url_join_with_different_query_and_params() {
|
||||
.contains("Mismatch, query param is: par_1=aaa&par_2=bbb"));
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("instead qs from params is: ?par_1=aaab&par_2=bbb"));
|
||||
.contains("instead query string from params is: ?par_1=aaab&par_2=bbb"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -201,7 +201,9 @@ fn url_join_with_invalid_params() {
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Key params has to be a record"));
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Key params has to be a record or a table"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -346,3 +348,83 @@ fn url_join_with_empty_params() {
|
||||
|
||||
assert_eq!(actual.out, "https://localhost/foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_join_with_list_in_params() {
|
||||
let actual = nu!(pipeline(
|
||||
r#"
|
||||
{
|
||||
"scheme": "http",
|
||||
"username": "usr",
|
||||
"password": "pwd",
|
||||
"host": "localhost",
|
||||
"params": {
|
||||
"par_1": "aaa",
|
||||
"par_2": ["bbb", "ccc"]
|
||||
},
|
||||
"port": "1234",
|
||||
} | url join
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"http://usr:pwd@localhost:1234?par_1=aaa&par_2=bbb&par_2=ccc"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_join_with_params_table() {
|
||||
let actual = nu!(pipeline(
|
||||
r#"
|
||||
{
|
||||
"scheme": "http",
|
||||
"username": "usr",
|
||||
"password": "pwd",
|
||||
"host": "localhost",
|
||||
"params": [
|
||||
["key", "value"];
|
||||
["par_1", "aaa"],
|
||||
["par_2", "bbb"],
|
||||
["par_1", "ccc"],
|
||||
["par_2", "ddd"],
|
||||
],
|
||||
"port": "1234",
|
||||
} | url join
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"http://usr:pwd@localhost:1234?par_1=aaa&par_2=bbb&par_1=ccc&par_2=ddd"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_join_with_params_invalid_table() {
|
||||
let actual = nu!(pipeline(
|
||||
r#"
|
||||
{
|
||||
"scheme": "http",
|
||||
"username": "usr",
|
||||
"password": "pwd",
|
||||
"host": "localhost",
|
||||
"params": (
|
||||
[
|
||||
["key", "value"];
|
||||
["par_1", "aaa"],
|
||||
["par_2", "bbb"],
|
||||
["par_1", "ccc"],
|
||||
["par_2", "ddd"],
|
||||
] ++ ["not a record"]
|
||||
),
|
||||
"port": "1234",
|
||||
} | url join
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("expected a table"));
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("not a table, contains non-record values"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user