Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse queries to a map of String to String using '&' and '=' #30

Open
seagreen opened this issue Aug 26, 2016 · 3 comments
Open

Parse queries to a map of String to String using '&' and '=' #30

seagreen opened this issue Aug 26, 2016 · 3 comments

Comments

@seagreen
Copy link

This would be a really useful utility function to have, though since I don't think & and = are actually part of the official URI specification I understand if you want to leave it out.

@ezrakilty
Copy link
Contributor

It's a reasonable suggestion. Let me ponder it.

A consequence of the fact that those symbols are not part of the spec is that, actually, there are a few different possible interpretations of the query string. For example, you suggest using a Map String String, but multiple occurrences of a key are allowed, and some people take advantage of this. Possibly a Map String [String] would be in order... but also, conceivably the order of key occurrences could matter, so that foo=1&bar=2&baz=3 is different from foo=1&baz=3&bar=2 (same key-value pairs, different order).

Let's leave this open to allow a discussion about it, in case a consensus emerges.

@seagreen
Copy link
Author

Great points. The thing to do (if you decide it's worth it) would probably be to make it a [(String, String)].

@JulianLeviston
Copy link

JulianLeviston commented Jan 9, 2018

I've been working on adjustments that do this... for my own specific uses... it keeps the query as two possible states, and parses them into one of those depending on the scheme — which dictates which query param separators and query param key-value separators to use. When it parses, it pulls it into an assocation list (ie [(String, String)] if it can, otherwise just parses it as a String.

When it pretty-prints, it joins them back according to the scheme... mind you, this doesn't allow for multiple separator types independent of the scheme — I hadn't really thought about that. (ie maybe using @ isntead of = and + instead of &, which is the one I'd wanted for the scheme active, for example).

So we have:

data URIQuery
    = URIQueryString String
    | URIQueryAssocList [(String, String)]
  deriving (Eq, Ord, Typeable, Data, Generic, NFData, Show)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants