Fix for wrap-nested-params and multi-valued parameters without '[]' #23

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants
@christophermaier

(sorry about the previous pull request... I missed a commit somehow)

I recently had to use a multiple select box on an HTML form, but didn't end the parameter name with "[]". wrap-params correctly transforms "foo=bar&foo=baz" into {"foo" ["bar" "baz"]}, but because the parameter was "foo" and not "foo[]", wrap-nested-params turned it into {"foo" "baz"}, eating all but the last value.

While this can be "fixed" by just calling the parameter "foo[]" from the beginning, it makes that a special case; you don't have to think about the brackets and whatnot when using the 'with-groups' macro in Hiccup, for instance (can't speak for other libraries like Enlive, though). In any event, wrap-nested-params was removing legitimate parameter values.

There is probably a better way to go about this; I just added another key to the middleware options map for a "multi-value-suffix" that defaults to "[]", in keeping with using the parse-nested-keys default parse function. Basically, if a multi-valued parameter is detected whose name doesn't end in the specified suffix, it gets added in the param-pairs function, making it appear "correct" to the rest of the machinery. It works, though.

Thanks,
Chris

christophermaier added some commits Jun 29, 2011

Add test showing failure of nested-params middleware on multi-valued …
…parameters that don't end in '[]', produced by e.g., multiple select elements.

For example, the query string "foo=bar&foo=baz".
@weavejester

This comment has been minimized.

Show comment Hide comment
@weavejester

weavejester Jul 6, 2011

Collaborator

As you say, there is probably a better solution for this than adding an additional option. I'll look into a fix for this.

Collaborator

weavejester commented Jul 6, 2011

As you say, there is probably a better solution for this than adding an additional option. I'll look into a fix for this.

@timewarrior

This comment has been minimized.

Show comment Hide comment
@timewarrior

timewarrior Dec 18, 2012

Hi
I am also facing this issue.
{"fooz" [{"baz" {"foo" "bar1"}} {"baz" {"foo" "bar2"}}]} is getting converted to {"fooz" {"baz" {"foo" "bar2"}}} losing the last value. For now I have disabled wrap-nested-params from my code. I would really appreciate if there was some fix for this.

Thanks
Anand

Hi
I am also facing this issue.
{"fooz" [{"baz" {"foo" "bar1"}} {"baz" {"foo" "bar2"}}]} is getting converted to {"fooz" {"baz" {"foo" "bar2"}}} losing the last value. For now I have disabled wrap-nested-params from my code. I would really appreciate if there was some fix for this.

Thanks
Anand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment