ring
ring copied to clipboard
`wrap-nested-params` does not parse `query-params` to produce a nested structure.
I am not sure if this is a bug or a deliberate design choice, but wrap-nested-params only returns nested structures on the :params key - not on :query-params (which it leaves in flat, unprocessed state).
eg, given the URL (http://localhost:8080/list/0?modal[id]=update-from), the following are the observed values in the two request keys in question:
15217 [qtp1776502451-20] INFO toto.view.query - (:params req)
=> {:modal {:id "update-from"}}
15234 [qtp1776502451-20] INFO toto.view.query - (:query-params req)
=> {"modal[id]" "update-from"}
I'd expect (hope?) that there would be a way to configure middleware such that :query-params map would reflect the nested structure: {:modal {:id "update-from"}}
Understanding that wrap-nested-params cannot be changed to do this without breaking backward compatibility, it would be a useful addition to have at least nest-params (https://github.com/ring-clojure/ring/blob/1.9.0/ring-core/src/ring/middleware/nested_params.clj#L47) be publicly visible so that the same parsing logic used for params can be reused by user code to parse query-params too. Either that, or an alternative middleware that could be added to apply the same parsing logic to :query-params that the current middleware applies to :params.
(The particular scenario here is using query parameters to control the display of a modal within a web page. Nested query parameters makes it considerably easier to group the parameters specific to the modal and remove them all in one shot when the modal is dismissed. So the idea is to look at just the :query-params nesting and build a new URL from that.)