Skip to content

Commit

Permalink
Fix percent encoding colons in query parameters
Browse files Browse the repository at this point in the history
Resolves #246
  • Loading branch information
ixti committed Aug 13, 2015
1 parent cba09b2 commit 1241744
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/http/client.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
require "forwardable"

require "cgi"
require "uri"

require "http/form_data"
require "http/options"
require "http/headers"
Expand Down Expand Up @@ -115,7 +112,7 @@ def verify_connection!(uri)
#
# @param [#to_s] uri
# @return [URI]
def make_request_uri(uri, options)
def make_request_uri(uri, opts)
uri = uri.to_s

if default_options.persistent? && uri !~ HTTP_OR_HTTPS_RE
Expand All @@ -124,9 +121,8 @@ def make_request_uri(uri, options)

uri = HTTP::URI.parse uri

if options.params && !options.params.empty?
params = CGI.parse(uri.query.to_s).merge(options.params || {})
uri.query = ::URI.encode_www_form params
if opts.params && !opts.params.empty?
uri.query = [uri.query, HTTP::URI.form_encode(opts.params)].compact.join("&")
end

# Some proxies (seen on WEBRick) fail if URL has
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/http/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def simple_response(body, status = 200)

client.get("http://example.com/?a[]=b&a[]=c", :params => {:d => "e"})
end

it "properly encodes colons" do
expect(HTTP::Request).to receive(:new) do |_, uri|
expect(uri.query).to eq "t=1970-01-01T00%3A00%3A00Z"
end

client.get("http://example.com/", :params => {:t => "1970-01-01T00:00:00Z"})
end
end

describe "passing json" do
Expand Down

0 comments on commit 1241744

Please sign in to comment.