Skip to content

Commit be7166c

Browse files
Merge pull request #252 from cayblood/master
Fixed superfluous ampersand when queries are embedded in paths
2 parents 49086d1 + 5db97a7 commit be7166c

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/httparty/request.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def query_string(uri)
174174
query_string_parts << options[:query] unless options[:query].nil?
175175
end
176176

177+
query_string_parts.reject!(&:empty?) unless query_string_parts == [""]
177178
query_string_parts.size > 0 ? query_string_parts.join('&') : nil
178179
end
179180

spec/httparty/request_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@
133133
URI.unescape(@request.uri.query).should == ""
134134
end
135135

136+
it "does not append an ampersand when queries are embedded in paths" do
137+
@request.path = "/path?a=1"
138+
@request.options[:query] = {}
139+
@request.uri.query.should == "a=1"
140+
end
141+
136142
it "does not duplicate query string parameters when uri is called twice" do
137143
@request.options[:query] = {:foo => :bar}
138144
@request.uri

0 commit comments

Comments
 (0)