[whatwg/url] Inconsistency when using URLSearchParams to mutate a URL (#478)

See: https://github.com/nodejs/node/issues/33037
Relates to: https://github.com/whatwg/url/issues/18

Because of the differences in `URLSearchParams` and `.search` stringification, encoding of the tilde (`~`) character becomes inconsistent when using `URLSearchParam` to mutate a `URL` instance... take the following examples for instance:

```js
const url = new URL('http://httpbin.org/anything?a=~');
url.search = url.searchParams.toString();
// becomes http://httpbin.org/anything?a=%7E
```

And...

(demonstrated in Node.js, but appears consistent across implementations)
```js
C:\Users\jasne\Projects\tmp>node
Welcome to Node.js v14.0.0.
Type ".help" for more information.
> const u = new URL('http://example.com/?a=~')
undefined
> u.toString()
'http://example.com/?a=~'
> u.searchParams.sort()
undefined
> u.toString()
'http://example.com/?a=%7E'
>
```

Per https://github.com/whatwg/url/issues/18, there are reasons why `URLSearchParam` uses different semantics for stringification, and I don't necessarily want to revisit those, but we *should* likely give consideration to what the expected behavior should be when `URLSearchParam` is used to mutate a `URL` instance. Which of the differing encoding semantics should take precedence?

/cc @szmarczak @bnoordhuis @Himself65 @hamper

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/478

Received on Friday, 24 April 2020 18:02:57 UTC