url
url copied to clipboard
Two "?"s added to url
I wanted to take an existing url and modify the query parameters. I noticed Url is just a record type so I figured the correct way to do this is
{ currentUrl
| query =
Url.Builder.toQuery [ Url.Builder.string "data" "test" ] |> Just
}
|> Url.toString
but when I did that the result was http://localhost:3000/??data=test instead of http://localhost:3000/?data=test.
This seems to be a bug or at least unintuitive behavior and what I ended up doing to make it work was add String.dropLeft 1 to the toQuery output.
Same problem (and same workaround) here.
Although you can't say that the behaviour of the toQuery function is wrong, it is a pitfall that the produced output is not a direct acceptable input for the query field of the Url record in the same package.
Just mentioning the exact requirements of the query field of the Url record and what toQuery actually produces in the docs would be immensely helpful to avoid this pitfall.