Fix #326 - Normalize query parameters to allow falsey values

This commit is contained in:
Steve Bazyl 2015-12-20 15:22:13 -08:00
parent 45a8dcba36
commit 1715fc9945
2 changed files with 25 additions and 1 deletions

View File

@ -264,7 +264,9 @@ module Google
# Temporary workaround for Hurley bug where the connection preference # Temporary workaround for Hurley bug where the connection preference
# is ignored and it uses nested anyway # is ignored and it uses nested anyway
req.url.query_class = Hurley::Query::Flat req.url.query_class = Hurley::Query::Flat
query.each { | k, v| req.url.query[k] = v } query.each do | k, v|
req.url.query[k] = normalize_query_value(v)
end
# End workaround # End workaround
apply_request_options(req) apply_request_options(req)
end end
@ -291,6 +293,19 @@ module Google
req.header.update(header) req.header.update(header)
req.options.timeout = options.timeout_sec req.options.timeout = options.timeout_sec
end end
private
def normalize_query_value(v)
case v
when Array
v.map { |v2| normalize_query_value(v2) }
when nil
nil
else
v.to_s
end
end
end end
end end
end end

View File

@ -272,4 +272,13 @@ RSpec.describe Google::Apis::Core::HttpCommand do
command.query['a'] = [1,2,3] command.query['a'] = [1,2,3]
command.execute(client) command.execute(client)
end end
it 'should send falsey query parameters' do
stub_request(:get, 'https://www.googleapis.com/zoo/animals?a=0&b=false')
.to_return(status: [200, ''])
command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
command.query['a'] = 0
command.query['b'] = false
command.execute(client)
end
end end