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:
parent
9e9e8d8e1b
commit
245869d1b3
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue