-
-
Notifications
You must be signed in to change notification settings - Fork 2
Description
First off, this is an AWESOME gem, because it uniquely provides functionality the built-in URI library is sorely lacking. Thank you for coding it.
The difficulty with this library I think is actually the fact that things are a lot more complicated than they seem at first glance. As a result, some thoughts on features this gem should seek to incorporate/aspire to..
- in some use cases (especially surrounding adding cryptographic signatures to API requests) the exact order of the parameters matters. Often it's alphabetical, but rules can vary. The best solution here is probably to ensure the exposed object returned by
#query_paramsis anOrderedHashrather than an ordinary one (if not an entirely custom object). - Rails in particular has a tendency to use arrays in form element names. So if I have an array of text fields and submit them, I run into this problem:
2.1.2 :009 > u = URI.parse("http://google.com/?list[items][]=1&list[items][]=2")
=> #<URI::HTTP:0x0000000aa61698 URL:http://google.com/?list[items][]=1&list[items][]=2>
2.1.2 :010 > u.query
=> "list[items][]=1&list[items][]=2"
2.1.2 :011 > u.query_params
=> {"list[items][]"=>"2"}
- Obviously the first issue here is that
u.query_paramsshould be returning aHashwith one key whose value is an array with the elements1and2, because that's whatparams[:list][:items]will return to a Rails controller. - A second issue is one with your implementation that's a bit more insidious. By the simple act of calling
#query_paramsit seems, without ever setting any values within the object. I have manipulated myURIobject. These lines in the IRB console immediately follow those above:
2.1.2 :012 > u.query
=> "list[items][]=2"
2.1.2 :013 > u
=> #<URI::HTTP:0x0000000aa61698 URL:http://google.com/?list[items][]=2>
This makes this gem completely unusable for me right now because so much as requireing it risks corrupting URLs that are parsed by the URI class in certain cases.
I'm very interested to see where you go with this though and might even be interested to work with you on fixing these bugs. Please let me know what you think in regards to my comments and if you develop some sort of plan for resolving the issues I have brought up.
Thanks,
Mike