-
Notifications
You must be signed in to change notification settings - Fork 365
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
Conversation
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. |
For now, as I understand, it comes from this line of self.last_response = access_token.send(method, "http://example.com#{path}", :body => params, :header => headers(method, path, params, request_headers)) The path is 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"]} |
Does OAuth2 client works in real conditions? |
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 :/ |
+1 nice investigation and good work. We should really excise webmock from the oauth client, but that's a separate issue. |
Serialize parameters with Arrays and Hashes properly.
Use params.to_query, taken from ActiveSupport, instead of custom serialization in RspecApiDocumentation::Dsl::Endpoint.
Difference:
Related to #48