Skip to content

Commit

Permalink
Don't duplicate query string arguments.
Browse files Browse the repository at this point in the history
During the course of an actual request, the Request#uri method is called more
than once. If the request's path is not relative, that method destructively
updates @path, and so parameters get duplicated each time uri is called. This
change clones the path first (and adds a lame test).
  • Loading branch information
sullman committed Feb 2, 2013
1 parent 783f878 commit e5bb508
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def request_uri(uri)
end

def uri
new_uri = path.relative? ? URI.parse("#{base_uri}#{path}") : path
new_uri = path.relative? ? URI.parse("#{base_uri}#{path}") : path.clone

# avoid double query string on redirects [#12]
unless redirect
Expand Down
6 changes: 6 additions & 0 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
URI.unescape(@request.uri.query).should == ""
end

it "does not duplicate query string parameters when uri is called twice" do
@request.options[:query] = {:foo => :bar}
@request.uri
@request.uri.query.should == "foo=bar"
end

context "when representing an array" do
it "returns a Rails style query string" do
@request.options[:query] = {:foo => %w(bar baz)}
Expand Down

0 comments on commit e5bb508

Please sign in to comment.