From e9a72f1c9e5fbf30ebec7f507a98a927dc3131c9 Mon Sep 17 00:00:00 2001 From: geemus Date: Mon, 11 Nov 2013 09:06:42 -0600 Subject: [PATCH] [aws] narrow scope of unf warning see #2320 --- lib/fog/aws.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index 141e3ead3..577bfae92 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -2,12 +2,6 @@ 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 extend Fog::Provider @@ -92,6 +86,14 @@ module Fog end def self.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