form_data
form_data copied to clipboard
Fix Urlencoded for nested Hashes (and Arrays)
One of the goals of this gem is to be free of dependencies and rovide everything on it's own. Basically we use URI right now because nobody had time to implement proper serializer. :D
One of the goals of this gem is to be free of dependencies and rovide everything on it's own.
Why? For what?
Basically we use URI right now because nobody had time to implement proper serializer. :D
URI has problems with nested Hashes and Arrays, you want to write own "proper" serializer. Rack already has its own serializer, you want to have, Addressable (possible) have (or had). Instead of multiple different implementations (some of which can be not able to catch some edge cases) I suggest to use one polished standard code (library).
Basically because this gem was born to encapsulate all the needed logic of serializing form data into multipart or urlencoded. I'm not saying I like using URI - I said we're using it just because we did not spend time to come with better solution. Using extra dependency for a very own purpose sound to me pretty bad practice and pretty smells like leftpad of node.js.
That's just my personal perception.
In other words - I'll be happy to consider PR that will bring provide better default encoder as part of FormData implementation.
Done…
Wow, floating bug from global state. I hate global state.
Are the plans to merge this? 😅
Sorry for a very slow reaction. I'll try to merge it this week.
I think I'm having an issue that this PR would fix. Basically, I'm trying to form encode an array and it doesn't work right:
HTTP::FormData.create({foo: ["bar", "baz"]}).to_s # => "foo=bar&foo=baz"
The correct output would be foo%5B%5D=bar&foo%5B%5D=baz.
The temporary, dirty fix can be HTTP::FormData.create({"foo[]": ["bar", "baz"]}).to_s (note the [] after foo)
Sorry for a very slow reaction. I'll try to merge it this week.
@ixti do you have any plan to merge this soon? we are having a similar problem because the nested hash