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

Serialize parameters with Arrays and Hashes properly. #51

Merged
merged 5 commits into from
Sep 19, 2012

Conversation

denyago
Copy link
Contributor

@denyago denyago commented Sep 18, 2012

Use params.to_query, taken from ActiveSupport, instead of custom serialization in RspecApiDocumentation::Dsl::Endpoint.

Difference:

  • before: "id_eq"=>"['1', '2']"
  • after: "id_eq"=>['1', '2']

Related to #48

@oestrich
Copy link
Contributor

Hello, thanks for the PR. However I think this might have broken the OAuth2 client. I made an addition to the oauth2 feature and it's currently failing. I'd add it onto the pull request, but a gist will have to do. https://gist.github.com/3746709

Somehow we're getting { "targets" => { "0" => "eric", "1" => "sam" }. I traced it around and I think the "targets[0]" comes in somewhere in Addressable.

@denyago
Copy link
Contributor Author

denyago commented Sep 19, 2012

For now, as I understand, it comes from this line of oauth2_mac_client:

self.last_response = access_token.send(method, "http://example.com#{path}", :body => params, :header => headers(method, path, params, request_headers))

The path is targets[]=eric&targets[]=sam. But after a request from access token made, it transforms to targets[0]=eric&targets[1]=sam.

This is issue with WebMock, it happens on https://github.com/bblimke/webmock/blob/v1.8.10/lib/webmock/rack_response.rb#L37. It normalizes URI, and makes it broken for Rack:

WebMock::Util::URI.normalize_uri("e.com?a[]=b&a[]=c") #=> #<Addressable::URI:0x3fdabb0f0f70 URI:http://e.com:80/?a%5B0%5D=b&a%5B1%5D=c>

WebMock::Util::URI.normalize_uri("e.com?a%5B%5D=b&a%5B%5D=c").query_values #=> {"a"=>["b", "c"]}
WebMock::Util::URI.normalize_uri("e.com?a%5B0%5D=b&a%5B1%5D=c").query_values #=> {"a"=>["b", "c"]}
WebMock::Util::URI.normalize_uri("e.com?a[0]=b&a[1]=c").query_values #=> {"a"=>["b", "c"]}
WebMock::Util::URI.normalize_uri("e.com?a[]=b&a[]=c").query_values #=> {"a"=>["b", "c"]}

Rack::Utils.parse_nested_query("a%5B%5D=b&a%5B%5D=c") #=> {"a"=>["b", "c"]}
Rack::Utils.parse_nested_query("a%5B0%5D=b&a%5B1%5D=c") #=> {"a"=>{"0"=>"b", "1"=>"c"}}
Rack::Utils.parse_nested_query("a[0]=b&a[1]=c") #=> {"a"=>{"0"=>"b", "1"=>"c"}}
Rack::Utils.parse_nested_query("a[]=b&a[]=c") #=> {"a"=>["b", "c"]}                      

@denyago
Copy link
Contributor Author

denyago commented Sep 19, 2012

Does OAuth2 client works in real conditions?

@denyago
Copy link
Contributor Author

denyago commented Sep 19, 2012

Hope, this helps.....

The only limitation, is:

let(:targets) { {'0'=>'strange', '1'=>'hash'} }

Won't work :'(

Also, WebMock 1.8.8 has normalize_uri fixed for nested arrays :/

@samwgoldman
Copy link
Contributor

+1 nice investigation and good work. We should really excise webmock from the oauth client, but that's a separate issue.

oestrich added a commit that referenced this pull request Sep 19, 2012
Serialize parameters with Arrays and Hashes properly.
@oestrich oestrich merged commit 38071c8 into zipmark:master Sep 19, 2012
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

Successfully merging this pull request may close these issues.

None yet

3 participants