Skip to content

Inconsistency when using URLSearchParams to mutate a URL #478

@jasnell

Description

@jasnell

See: nodejs/node#33037
Relates to: #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:

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)

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 #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs concrete proposalMoving the issue forward requires someone to figure out a detailed planneeds implementer interestMoving the issue forward requires implementers to express interesttopic: api

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions