Made the 'unf' dependency optional.

If you don't have 'unf' installed and you use an AWS adapter, you'll get a message about how your strings might not be properly escaped.  If the gem is available, we'll use it.
This commit is contained in:
Kevin Menard 2013-10-25 10:54:28 -04:00
parent 69988cbc1d
commit 8d808d4325
3 changed files with 8 additions and 4 deletions

View File

@ -50,7 +50,6 @@ Gem::Specification.new do |s|
s.add_dependency('net-ssh', '>=2.1.3')
s.add_dependency('nokogiri', '~>1.5')
s.add_dependency('ruby-hmac')
s.add_dependency('unf')
## List your development dependencies here. Development dependencies are
## those that are only needed during development

View File

@ -1,7 +1,12 @@
require 'fog/core'
require 'fog/aws/credential_fetcher'
require 'fog/aws/signaturev4'
begin
require 'unf/normalizer'
rescue LoadError
Fog::Logger.warning("Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.")
end
module Fog
module AWS
@ -87,7 +92,7 @@ module Fog
end
def self.escape(string)
string = ::UNF::Normalizer.normalize(string, :nfc)
string = defined?(::UNF::Normalizer) ? ::UNF::Normalizer.normalize(string, :nfc) : string
string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}

View File

@ -170,7 +170,7 @@ module Fog
# NOTE: differs from Fog::AWS.escape by NOT escaping `/`
def escape(string)
string = ::UNF::Normalizer.normalize(string, :nfc)
string = defined?(::UNF::Normalizer) ? ::UNF::Normalizer.normalize(string, :nfc) : string
string.gsub(/([^a-zA-Z0-9_.\-~\/]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}