Wulan reads a parcel label with new URL(): host, pathname, the query notes, and the hash. Which parts really reach the gudang? An interactive URL &…
Why it matters
Filters, paging, share links, OAuth callbacks: all read and write URLs. The browser’s own parser knows the rules for encoding, repeated keys, default ports and the hash; a home-made parser (split, a regex) almost always leaks at one of them.
The key idea
Let the browser read the URL
Common mistakes
Parsing the query with split('?')[1].split('&') Nothing is decoded (+ and %3D stay raw), the hash rides in the last value, a value holding = is cut. Use new URL(text).searchParams.
Forgetting a key can repeat?id=1&id=2 is valid. .get() gives the first; .getAll('id') all of them; .set() overwrites them all with one.
Encoding a value yourself, then set() again Double encoding: % becomes %25, and the server reads teh%20%26%20kopi. searchParams.set() already encodes; give it the raw value.
Try it in this playground
Read the label with new URL() Situation 1: the parts come apart, host = hostname + port.
getAll() on a repeated key Situation 2: get('id') gives only the first; getAll('id') gives them all.
set() a value with a space or & A space becomes +, & becomes %26 in the href; the gudang still reads the original value.
Send a URL with a hash Situation 4: the hash is not sent; the gudang never sees it.