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

Better URL escaping for Rackspace Cloud Files.

URI.escape doesn't encode question marks properly, CGI.escape doesn't encode
spaces properly.  So we create an escape class method for Fog::Rackspace that
does the CGI.escape methods, only encoding spaces as %20.

This makes things work properly with Rackspace Cloud Files.
This commit is contained in:
H. Wade Minter 2011-09-16 23:46:22 -04:00
parent cb1d5919f0
commit 934ff8a993
11 changed files with 19 additions and 9 deletions

View file

@ -70,5 +70,12 @@ module Fog
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key) !['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
end end
end end
# CGI.escape, but without special treatment on spaces
def self.escape(str,extra_exclude_chars = '')
str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
end
end
end end
end end

View file

@ -12,7 +12,7 @@ module Fog
request( request(
:expects => 204, :expects => 204,
:method => 'DELETE', :method => 'DELETE',
:path => URI.escape(name) :path => Fog::Rackspace.escape(name)
) )
end end

View file

@ -13,7 +13,7 @@ module Fog
request( request(
:expects => 204, :expects => 204,
:method => 'DELETE', :method => 'DELETE',
:path => "#{URI.escape(container)}/#{URI.escape(object)}" :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
) )
end end

View file

@ -33,7 +33,7 @@ module Fog
request( request(
:expects => 200, :expects => 200,
:method => 'GET', :method => 'GET',
:path => URI.escape(container), :path => Fog::Rackspace.escape(container),
:query => {'format' => 'json'}.merge!(options) :query => {'format' => 'json'}.merge!(options)
) )
end end

View file

@ -14,7 +14,7 @@ module Fog
:block => block, :block => block,
:expects => 200, :expects => 200,
:method => 'GET', :method => 'GET',
:path => "#{URI.escape(container)}/#{URI.escape(object)}" :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
}, false, &block) }, false, &block)
end end

View file

@ -17,7 +17,7 @@ module Fog
request( request(
:expects => 204, :expects => 204,
:method => 'HEAD', :method => 'HEAD',
:path => URI.escape(container), :path => Fog::Rackspace.escape(container),
:query => {'format' => 'json'} :query => {'format' => 'json'}
) )
end end

View file

@ -13,7 +13,7 @@ module Fog
request({ request({
:expects => 200, :expects => 200,
:method => 'HEAD', :method => 'HEAD',
:path => "#{URI.escape(container)}/#{URI.escape(object)}" :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
}, false) }, false)
end end

View file

@ -12,7 +12,7 @@ module Fog
request( request(
:expects => [201, 202], :expects => [201, 202],
:method => 'PUT', :method => 'PUT',
:path => URI.escape(name) :path => Fog::Rackspace.escape(name)
) )
end end

View file

@ -19,7 +19,7 @@ module Fog
:expects => 201, :expects => 201,
:headers => headers, :headers => headers,
:method => 'PUT', :method => 'PUT',
:path => "#{URI.escape(container)}/#{URI.escape(object)}" :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
) )
end end

View file

@ -10,7 +10,7 @@ module Fog
# * object<~String> - Name for object # * object<~String> - Name for object
# #
def put_object_manifest(container, object) def put_object_manifest(container, object)
path = "#{URI.escape(container)}/#{URI.escape(object)}" path = "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
request( request(
:expects => 201, :expects => 201,
:headers => {'X-Object-Manifest' => path}, :headers => {'X-Object-Manifest' => path},

View file

@ -0,0 +1,3 @@
Shindo.tests('Rackspace | url_encoding', ['rackspace']) do
returns( Fog::Rackspace.escape( "is this my file?.jpg" ) ) { "is%20this%20my%20file%3F.jpg" }
end