Convert query values explicitly to strings (#810)

This commit is contained in:
Daniel Azuma 2019-07-29 11:29:32 -07:00 committed by GitHub
parent b314e0df2b
commit 4e38887c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -156,7 +156,7 @@ module Google
normalize_unicode = options.normalize_unicode
end
self.url = url.expand(params, nil, normalize_unicode) if url.is_a?(Addressable::Template)
url.query_values = query.merge(url.query_values || {})
url.query_values = normalize_query_values(query).merge(url.query_values || {})
if allow_form_encoding?
@form_encoded = true
@ -422,6 +422,13 @@ module Google
end
end
def normalize_query_values(input)
input.inject({}) do |h, (k, v)|
h[k] = normalize_query_value(v)
h
end
end
def normalize_query_value(v)
case v
when Array

View File

@ -419,6 +419,17 @@ RSpec.describe Google::Apis::Core::HttpCommand do
command.execute(client)
end
it 'should send DateTime query parameters' do
stub_request(:get, 'https://www.googleapis.com/zoo/animals?a=2019-06-22T13:51:37-07:00&b=2019-06-22T13:51:37-07:00&b=2019-07-23T14:54:12-07:00')
.to_return(status: [200, ''])
command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
date1 = DateTime.new(2019, 6, 22, 13, 51, 37, "-0700")
date2 = DateTime.new(2019, 7, 23, 14, 54, 12, "-0700")
command.query['a'] = date1
command.query['b'] = [date1, date2]
command.execute(client)
end
it 'should form encode parameters when method is POST and no body present' do
stub_request(:post, 'https://www.googleapis.com/zoo/animals')
.with(body: 'a=1&a=2&a=3&b=hello&c=&d=0')