Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Arrays and other thoughts #4

Open
Labels
@mvastola

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_params is an OrderedHash rather 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_params should be returning a Hash with one key whose value is an array with the elements 1 and 2, because that's what params[: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_params it seems, without ever setting any values within the object. I have manipulated my URI object. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /