elixir-plug / plug

Compose web applications with functions
https://hex.pm/packages/plug
Other
2.84k stars 582 forks source link

Query decoding implementation #1106

Closed LostKobrakai closed 2 years ago

LostKobrakai commented 2 years ago

There seems to be some inconsistency between ordering of values in queries and their decoded value of Plug.Conn.Query. Encoding seems to prefer a map for a key over a string value for the same key independent of ordering. I'm wondering if that's correct like that, given the same isn't the case e.g. for lists like shown below:

iex(4)> Plug.Conn.Query.decode("form[key]=trim&form[key][]=abc")
%{"form" => %{"key" => ["abc"]}}
iex(5)> Plug.Conn.Query.decode("form[key][]=abc&form[key]=trim")
%{"form" => %{"key" => "trim"}}

iex(6)> Plug.Conn.Query.decode("form[key]=trim&form[key][][key]=abc")
%{"form" => %{"key" => [%{"key" => "abc"}]}}
iex(7)> Plug.Conn.Query.decode("form[key][][key]=abc&form[key]=trim")
%{"form" => %{"key" => "trim"}}

iex(8)> Plug.Conn.Query.decode("form[key]=trim&form[key][0][key]=abc")           
%{"form" => %{"key" => %{"0" => %{"key" => "abc"}}}}
iex(9)> Plug.Conn.Query.decode("form[key][0][key]=abc&form[key]=trim")
%{"form" => %{"key" => %{"0" => %{"key" => "abc"}}}}
josevalim commented 2 years ago

Yeah, a PR unifying would be welcome!