mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
fix S3 vs EC2 escaping differences
This commit is contained in:
parent
3e52caa18b
commit
00da79c3cb
3 changed files with 19 additions and 8 deletions
|
@ -161,11 +161,19 @@ module Fog
|
|||
end
|
||||
|
||||
def object_to_path(object_name=nil)
|
||||
'/' + Fog::AWS.escape(object_name.to_s).gsub('%2F','/')
|
||||
'/' + escape(object_name.to_s).gsub('%2F','/')
|
||||
end
|
||||
|
||||
def bucket_to_path(bucket_name, path=nil)
|
||||
"/#{Fog::AWS.escape(bucket_name.to_s)}#{path}"
|
||||
"/#{escape(bucket_name.to_s)}#{path}"
|
||||
end
|
||||
|
||||
# NOTE: differs fram Fog::AWS.escape by NOT escaping `/`
|
||||
def escape(string)
|
||||
string = Unicode::normalize_C(string)
|
||||
string.gsub(/([^a-zA-Z0-9_.\-~\/]+)/) {
|
||||
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
|
||||
}
|
||||
end
|
||||
|
||||
# Transforms things like bucket_name, object_name, region
|
||||
|
@ -232,7 +240,7 @@ module Fog
|
|||
def params_to_url(params)
|
||||
query = params[:query] && params[:query].map do |key, value|
|
||||
if value
|
||||
[key, Fog::AWS.escape(value.to_s)].join('=')
|
||||
[key, escape(value.to_s)].join('=')
|
||||
else
|
||||
key
|
||||
end
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
# encoding: utf-8
|
||||
|
||||
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
|
||||
returns( Fog::AWS.escape( "'Stöp!' said Fred_-~./" ) ) { "%27St%C3%B6p%21%27%20said%20Fred_-~.%2F" }
|
||||
|
||||
tests('Keys should be canonicalised using Unicode NFC') do
|
||||
returns( Fog::AWS.escape( ["00E9".to_i(16)].pack("U*") ) ) { "%C3%A9" }
|
||||
|
|
7
tests/aws/storage_tests.rb
Normal file
7
tests/aws/storage_tests.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# encoding: utf-8
|
||||
|
||||
Shindo.tests('AWS Storage | escape', ['aws']) do
|
||||
tests('Keys can contain a hierarchical prefix which should not be escaped') do
|
||||
returns( Fog::Storage::AWS.new.send(:escape, "key/with/prefix") ) { "key/with/prefix" }
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue