Skip to content

add table params support to url join and url build-query - #14239

Merged
fdncred merged 10 commits into
nushell:mainfrom
Bahex:url-build-query-table
Nov 6, 2024
Merged

fdncred merged 10 commits into
nushell:mainfrom
Bahex:url-build-query-table

Conversation

@Bahex

@Bahex Bahex commented Nov 3, 2024

Copy link
Copy Markdown
Member

Add table<key, value> support to url join for the params field, and as input to url build-query #14162

Description

{
    "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

[
    ["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

Bahex added 6 commits November 3, 2024 08:02
Transforms key value pairs in the form `table<key, value>` into a query
string

[[key, value];
 [a, one],
 [a, two],
 [b, three],
] => "a=one&a=two&b=three"
- `value`'s span can be derived from `value` and does not need to be
  supplied separately
- however head span can not be derived from other parameters and may be
  used error messages
NOTE: This means previously allowed single row table inputs which worked
the same as record inputs are no longer accepted.
Also reduce nesting in code.
- update invalid param error check to be more specific
- add check for list values in params
- add check for valid and invalid tables as params
@Bahex

Bahex commented Nov 3, 2024

Copy link
Copy Markdown
Member Author

Looks like there are integration tests that expected "Mismatch, qs from params" in the error text

@fdncred

fdncred commented Nov 3, 2024

Copy link
Copy Markdown
Contributor

oops, sorry for breaking things. just thought query string was easier to understand.

@sholderbach sholderbach added the A:networking All about our `http` and `url` commands and everything going accross the network. label Nov 4, 2024
@fdncred

fdncred commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

conflicts now that your other pr landed, when you have time.

@fdncred fdncred added the deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way label Nov 6, 2024
@fdncred
fdncred merged commit c7e128e into nushell:main Nov 6, 2024
@fdncred

fdncred commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

Thanks.

@github-actions github-actions Bot added this to the v0.100.0 milestone Nov 6, 2024
NotTheDr01ds pushed a commit to NotTheDr01ds/nushell that referenced this pull request Nov 8, 2024
…#14239)

Add `table<key, value>` support to `url join` for the `params` field,
and as input to `url build-query` nushell#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 <[email protected]>
@Bahex
Bahex deleted the url-build-query-table branch March 22, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:networking All about our `http` and `url` commands and everything going accross the network. deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants