1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|storage] warn/load unf as needed

This commit is contained in:
geemus 2013-11-15 10:04:37 -06:00
parent 9e9e8d8e1b
commit 245869d1b3

View file

@ -174,6 +174,14 @@ module Fog
# NOTE: differs from Fog::AWS.escape by NOT escaping `/`
def escape(string)
unless @unf_loaded_or_warned
begin
require('unf/normalizer')
rescue LoadError
Fog::Logger.warning("Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.")
end
@unf_loaded_or_warned = true
end
string = defined?(::UNF::Normalizer) ? ::UNF::Normalizer.normalize(string, :nfc) : string
string.gsub(/([^a-zA-Z0-9_.\-~\/]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase