Don't normalize unicode in templates (fixed #557 + GCS issues)

This commit is contained in:
Steve Bazyl 2017-03-30 12:33:49 -07:00
parent c4d0ed5d3c
commit 5447ddb7c0
6 changed files with 36 additions and 6 deletions

View File

@ -1,6 +1,9 @@
# 0.11.0 # 0.11.0
* *Breaking Change* - Fix handling of large numbers during code generation. Previously the * *Breaking Change* - Fix handling of large numbers during code generation. Previously the
uint64/int64 formats were passed through as strings. They are now coerced to/from Fixnum/Bignum types uint64/int64 formats were passed through as strings. They are now coerced to/from Fixnum/Bignum types
* *Breaking Change* - No longer normalize unicode strings in URI templates. Mostly affects
Cloud Storage, but other APIs with unicode strings in paths may be affected. Old behavior
can be restored using the `normalize_unicode` request option.
* Remove Hurley as dependency. May cause minor breaking changes if directly accessing the underlying * Remove Hurley as dependency. May cause minor breaking changes if directly accessing the underlying
client connection. client connection.
* Drop compatibility with Rails 3.x since that is no longer supported by the Rails community. * Drop compatibility with Rails 3.x since that is no longer supported by the Rails community.

View File

@ -1,4 +1,4 @@
# Migrating from version `0.8.x` to `0.9` # Migrating from version `0.8.x` to `0.9` and above
Many changes and improvements have been made to the `google-api-ruby-client` Many changes and improvements have been made to the `google-api-ruby-client`
library to bring it to `0.9`. If you are starting a new project or haven't used library to bring it to `0.9`. If you are starting a new project or haven't used

View File

@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'representable', '~> 3.0' spec.add_runtime_dependency 'representable', '~> 3.0'
spec.add_runtime_dependency 'retriable', '>= 2.0', '< 4.0' spec.add_runtime_dependency 'retriable', '>= 2.0', '< 4.0'
spec.add_runtime_dependency 'addressable', '~> 2.3' spec.add_runtime_dependency 'addressable', '>= 2.5.1'
spec.add_runtime_dependency 'mime-types', '>= 3.0' spec.add_runtime_dependency 'mime-types', '>= 3.0'
spec.add_runtime_dependency 'googleauth', '~> 0.5' spec.add_runtime_dependency 'googleauth', '~> 0.5'
spec.add_runtime_dependency 'httpclient', '>= 2.8.1', '< 3.0' spec.add_runtime_dependency 'httpclient', '>= 2.8.1', '< 3.0'

View File

@ -139,8 +139,12 @@ module Google
# @private # @private
# @return [void] # @return [void]
def prepare! def prepare!
header.update(options.header) if options && options.header normalize_unicode = true
self.url = url.expand(params) if url.is_a?(Addressable::Template) if options
header.update(options.header) if options.header
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 = query.merge(url.query_values || {})
if allow_form_encoding? if allow_form_encoding?

View File

@ -26,7 +26,8 @@ module Google
:retries, :retries,
:header, :header,
:timeout_sec, :timeout_sec,
:open_timeout_sec) :open_timeout_sec,
:normalize_unicode)
# General client options # General client options
class ClientOptions class ClientOptions
@ -56,6 +57,8 @@ module Google
# @return [Fixnum] How long, in seconds, before failed connections time out # @return [Fixnum] How long, in seconds, before failed connections time out
# @!attribute [rw] header # @!attribute [rw] header
# @return [Hash<String,String] Additional HTTP headers to include in requests # @return [Hash<String,String] Additional HTTP headers to include in requests
# @!attribute [rw] normalize_unicode
# @return [Boolean] True if unicode strings should be normalized in path parameters
# Get the default options # Get the default options
# @return [Google::Apis::RequestOptions] # @return [Google::Apis::RequestOptions]
@ -78,8 +81,8 @@ module Google
ClientOptions.default.use_net_http = false ClientOptions.default.use_net_http = false
ClientOptions.default.application_name = 'unknown' ClientOptions.default.application_name = 'unknown'
ClientOptions.default.application_version = '0.0.0' ClientOptions.default.application_version = '0.0.0'
RequestOptions.default.retries = 0 RequestOptions.default.retries = 0
RequestOptions.default.open_timeout_sec = 20 RequestOptions.default.open_timeout_sec = 20
RequestOptions.default.normalize_unicode = false
end end
end end

View File

@ -306,4 +306,24 @@ RSpec.describe Google::Apis::Core::HttpCommand do
command.options.retries = 0 command.options.retries = 0
expect { command.execute(client) }.to raise_error(Google::Apis::RateLimitError) expect { command.execute(client) }.to raise_error(Google::Apis::RateLimitError)
end end
it 'should not normalize unicode values by default' do
stub_request(:get, 'https://www.googleapis.com/Cafe%CC%81').to_return(status: [200, ''])
template = Addressable::Template.new('https://www.googleapis.com/{path}')
command = Google::Apis::Core::HttpCommand.new(:get, template)
command.params[:path] = "Cafe\u0301"
command.options.retries = 0
command.execute(client)
end
it 'should normalize unicode values when requested' do
stub_request(:get, 'https://www.googleapis.com/Caf%C3%A9').to_return(status: [200, ''])
template = Addressable::Template.new('https://www.googleapis.com/{path}')
command = Google::Apis::Core::HttpCommand.new(:get, template)
command.params[:path] = "Cafe\u0301"
command.options.retries = 0
command.options.normalize_unicode = true
command.execute(client)
end
end end