Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLSearchParam.append Encoding Behavior #37676

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions files/en-us/web/api/urlsearchparams/append/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ interface appends a specified key/value pair as a new search parameter.
As shown in the example below, if the same key is appended multiple times it will
appear in the parameter string multiple times for each value.

As shown in the second example below, both `name` and `value` will be automatically
sublimemm marked this conversation as resolved.
Show resolved Hide resolved
encoded to be URL safe.


sublimemm marked this conversation as resolved.
Show resolved Hide resolved
## Syntax

```js-nolint
Expand All @@ -34,6 +38,8 @@ None ({{jsxref("undefined")}}).
## Examples

```js
//Example: Adding the same param multiple times

let url = new URL("https://example.com?foo=1&bar=2");
let params = new URLSearchParams(url.search);

Expand All @@ -42,6 +48,17 @@ params.append("foo", 4);
//Query string is now: 'foo=1&bar=2&foo=4'
```

```js
//Example: Demostrating the encoding behavior

const params = new URLSearchParams();

params.append('needsEncoding$%&$#@++++++','needsEncoding$#&*@#()+++++' )
sublimemm marked this conversation as resolved.
Show resolved Hide resolved
params.toString();
//"needsEncoding%24%25%26%24%23%40%2B%2B%2B%2B%2B%2B=needsEncoding%24%23%26*%40%23%28%29%2B%2B%2B%2B%2B"

sublimemm marked this conversation as resolved.
Show resolved Hide resolved
```

## Specifications

{{Specifications}}
Expand Down
Loading