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

Merge pull request #2110 from github/fix-aws-escape

Fix aws escape
This commit is contained in:
Wesley Beary 2013-09-17 06:40:57 -07:00
commit 0f8cc3c27f
3 changed files with 16 additions and 1 deletions

View file

@ -50,6 +50,7 @@ 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('unicode', "~> 0.4.4")
## List your development dependencies here. Development dependencies are
## those that are only needed during development

View file

@ -1,6 +1,7 @@
require 'fog/core'
require 'fog/aws/credential_fetcher'
require 'fog/aws/signaturev4'
require 'unicode'
module Fog
module AWS
extend Fog::Provider
@ -85,7 +86,8 @@ module Fog
end
def self.escape(string)
string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
string = Unicode::normalize_C(string)
string.gsub(/([^a-zA-Z0-9_.\-~\/]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}
end

View file

@ -2,4 +2,16 @@
Shindo.tests('AWS | signed_params', ['aws']) do
returns( Fog::AWS.escape( "'Stöp!' said Fred_-~." ) ) { "%27St%C3%B6p%21%27%20said%20Fred_-~." }
tests('Keys can contain a hierarchical prefix which should not be escaped') do
returns( Fog::AWS.escape( "key/with/prefix" ) ) { "key/with/prefix" }
end
tests('Keys should be canonicalised using Unicode NFC') do
returns( Fog::AWS.escape( ["00E9".to_i(16)].pack("U*") ) ) { "%C3%A9" }
tests('Characters with combining mark should be combined and then escaped') do
returns( Fog::AWS.escape( ["0065".to_i(16), "0301".to_i(16)].pack("U*") ) ) { "%C3%A9" }
end
end
end