http-types icon indicating copy to clipboard operation
http-types copied to clipboard

Parsing query strings with keys of the same name

Open alexmingoia opened this issue 10 years ago • 3 comments

The browser behavior (and standard if I can dig up the forms spec) of HTML forms with array-like values is to include a query string with repeated keys.

This multi-select:

<select name="colors" multiple>
  <option value="orange">orange</option>
  <option value="purple">purple</option>
</select>

Will result in ?colors=orange&colors=purple if both options are selected. Instead of parsing this as a list, parseQuery ignores the second value. Furthermore, the query is represented as a lookup map of bytestrings, so has no notion of multiple values per key.

The reason I bring this issue up is this use case: basic HTML form with a multi-select and no JS and a haskell backend using http-types. The http-types Query type and parsers fail that use case.

alexmingoia avatar Oct 22 '15 04:10 alexmingoia

Fair point. How about this? We leave Query and QueryItem as is, but make a generic Query-like type that allows putting in Maybe or [], and we just use a generic "append" operation that either replaces or adds an element.

I would most welcome pull requests for this! :-)

aristidb avatar Oct 22 '15 18:10 aristidb

To clarify: The parseQuery function would always work in terms of the generic type.

aristidb avatar Oct 22 '15 18:10 aristidb

I'm pretty sure parseQuery just creates a list of key-value pairs. (at least currently)

Vlix avatar Nov 30 '23 20:11 Vlix