evancz / url-parser

Parse URLs into nicely structured data
http://package.elm-lang.org/packages/evancz/url-parser/latest/
BSD 3-Clause "New" or "Revised" License
114 stars 29 forks source link

Example with query params doesn't work #23

Closed ckoster22 closed 7 years ago

ckoster22 commented 7 years ago

I'm attempting to figure out how to parse a path or hash with multiple query parameters, something like a (<&>) function. In going through the docs I noticed several examples with query parameters do not work. For example, the following code from the (\<?>) example does not work in Elm repl:

> parsePath (s "blog" <?> stringParam "search") (Location "" "" "" "" "" "" "/blog/?search=cats" "" "" "" "")
Nothing : Maybe.Maybe (Maybe.Maybe String)

This is an incremental step in working up to an example with a path like "/blog?search=cats&order=desc". Guidance on parsing multiple query parameters would also be appreciated.

process-bot commented 7 years ago

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

ckoster22 commented 7 years ago

Closing this issue as this was a problem with mocking a Location specifically for parsePath. Correctly mocking the search string yielded expected results.

> parsePath (s "blog" <?> stringParam "search") (Location "" "" "" "" "" "" "/blog" "?search=cats" "" "" "")
Just (Just "cats") : Maybe.Maybe (Maybe.Maybe String)

However, this will only work with parsePath. It appears that if you attempt to use query parameters with parseHash the UrlParser.*param functions do not work because the Navigation.Location groups the hash and query string together into the hash attribute, rather than splitting out the query string into the search attribute on Location.