elm / url

Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
https://package.elm-lang.org/packages/elm/url/latest/
BSD 3-Clause "New" or "Revised" License
75 stars 43 forks source link

Two "?"s added to url #37

Open MartinSStewart opened 4 years ago

MartinSStewart commented 4 years ago

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.

tmohme commented 4 years ago

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.