Skip to content

Url split query - #14211

Merged
fdncred merged 5 commits into
nushell:mainfrom
Bahex:url-split-query
Nov 6, 2024
Merged

fdncred merged 5 commits into
nushell:mainfrom
Bahex:url-split-query

Conversation

@Bahex

@Bahex Bahex commented Oct 30, 2024

Copy link
Copy Markdown
Member

Addresses the following points from #14162

  • There is no built-in counterpart to url build-query for splitting a query string

There is from url, which, due to naming, is a little hard to discover and suffers from the following point

  • url parse can create records with duplicate keys
  • url parse's params should either:
    • group the same keys into a list.
    • instead of a record, be a key-value table. (table<key: string, value: string>)

Description

url split-query

Counterpart to url build-query, splits a url encoded query string to key value pairs, represented as table<key: string, value: string>

> "a=one&a=two&b=three" | url split-query
╭───┬─────┬───────╮
│ # │ key │ value │
├───┼─────┼───────┤
│ 0 │ a   │ one   │
│ 1 │ a   │ two   │
│ 2 │ b   │ three │
╰───┴─────┴───────╯

url parse

The output's param field is now a table as well, mirroring the new url split-query

> 'http://localhost?a=one&a=two&b=three' | url parse
╭──────────┬─────────────────────╮
│ scheme   │ http                │
│ username │                     │
│ password │                     │
│ host     │ localhost           │
│ port     │                     │
│ path     │ /                   │
│ query    │ a=one&a=two&b=three │
│ fragment │                     │
│          │ ╭───┬─────┬───────╮ │
│ params   │ │ # │ key │ value │ │
│          │ ├───┼─────┼───────┤ │
│          │ │ 0 │ a   │ one   │ │
│          │ │ 1 │ a   │ two   │ │
│          │ │ 2 │ b   │ three │ │
│          │ ╰───┴─────┴───────╯ │
╰──────────┴─────────────────────╯

User-Facing Changes

  • url parse's output has the mentioned change, which is backwards incompatible.

@Bahex

Bahex commented Oct 30, 2024

Copy link
Copy Markdown
Member Author

Forgot about the integration tests since my computer doesn't have enough space to compile and run the whole test suite 🤦

@sholderbach sholderbach added notes:breaking-changes Noted in Breaking Changes section new-command deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way A:networking All about our `http` and `url` commands and everything going accross the network. labels Oct 30, 2024
@fdncred
fdncred merged commit 3182adb into nushell:main Nov 6, 2024
@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
Addresses the following points from nushell#14162

> - There is no built-in counterpart to url build-query for splitting a
query string

There is `from url`, which, due to naming, is a little hard to discover
and suffers from the following point

> - url parse can create records with duplicate keys
> - url parse's params should either:
>   - ~group the same keys into a list.~
> - instead of a record, be a key-value table. (table<key: string,
value: string>)

# Description

## `url split-query`

Counterpart to `url build-query`, splits a url encoded query string to
key value pairs, represented as `table<key: string, value: string>`

```
> "a=one&a=two&b=three" | url split-query
╭───┬─────┬───────╮
│ # │ key │ value │
├───┼─────┼───────┤
│ 0 │ a   │ one   │
│ 1 │ a   │ two   │
│ 2 │ b   │ three │
╰───┴─────┴───────╯
```

## `url parse`

The output's `param` field is now a table as well, mirroring the new
`url split-query`

```
> 'http://localhost?a=one&a=two&b=three' | url parse
╭──────────┬─────────────────────╮
│ scheme   │ http                │
│ username │                     │
│ password │                     │
│ host     │ localhost           │
│ port     │                     │
│ path     │ /                   │
│ query    │ a=one&a=two&b=three │
│ fragment │                     │
│          │ ╭───┬─────┬───────╮ │
│ params   │ │ # │ key │ value │ │
│          │ ├───┼─────┼───────┤ │
│          │ │ 0 │ a   │ one   │ │
│          │ │ 1 │ a   │ two   │ │
│          │ │ 2 │ b   │ three │ │
│          │ ╰───┴─────┴───────╯ │
╰──────────┴─────────────────────╯
```

# User-Facing Changes

- `url parse`'s output has the mentioned change, which is backwards
incompatible.
ErichDonGubler added a commit to erichdongubler-mozilla/fx-scripts that referenced this pull request Dec 20, 2024
@Bahex
Bahex deleted the url-split-query 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 new-command notes:breaking-changes Noted in Breaking Changes section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants