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

URI query decoding. #1

Closed
CrowdHailer opened this issue Jun 11, 2016 · 3 comments
Closed

URI query decoding. #1

CrowdHailer opened this issue Jun 11, 2016 · 3 comments

Comments

@CrowdHailer
Copy link
Owner

I am unclear why elixirs URL library does not support lists when encoding and decoding query strings

URI.decode_query("foo[]=1&foo[]=2")
# %{"foo[]" => "2"}
# But I would expect %{"foo" => ["1", "2"]} 

This is obviously a deliberate choice as in the docs is this quote

Keys and values can be any term that implements the String.Chars protocol, except lists which are explicitly forbidden.

elixir-lang/elixir#2876 Suggests just using plug but I will be instead copy and pasting as raxx cannot depend on plug.

@CrowdHailer
Copy link
Owner Author

Similar to #20 The specification for query parameters doesn't include nesting, however it doesn't to any degree specify what to do with multiple keys.

The solution is to write a URI2/Raxx.URI module.
Things to change:

  • always return errors. URI.decode_www_form throws an error
  • URI2.Query.decode() -> [{key => value}] both strings
  • create a collapse to nested functionality

@CrowdHailer
Copy link
Owner Author

This is handled in version 0.6.0

@T-Spoon
Copy link

T-Spoon commented Jul 13, 2019

For anyone curious - URI2 is no longer part of this project - so decoding lists doesn't work as expected:

https://github.com/CrowdHailer/raxx/blob/19efea5e444e3a87fd8abee541dd0593ab0f782d/CHANGELOG.md#0150---2018-04-18

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

2 participants