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:
parent
cb1d5919f0
commit
934ff8a993
11 changed files with 19 additions and 9 deletions
|
@ -70,5 +70,12 @@ module Fog
|
|||
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
|
||||
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
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => URI.escape(name)
|
||||
:path => Fog::Rackspace.escape(name)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "#{URI.escape(container)}/#{URI.escape(object)}"
|
||||
:path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ module Fog
|
|||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => URI.escape(container),
|
||||
:path => Fog::Rackspace.escape(container),
|
||||
:query => {'format' => 'json'}.merge!(options)
|
||||
)
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
:block => block,
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "#{URI.escape(container)}/#{URI.escape(object)}"
|
||||
:path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
|
||||
}, false, &block)
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
request(
|
||||
:expects => 204,
|
||||
:method => 'HEAD',
|
||||
:path => URI.escape(container),
|
||||
:path => Fog::Rackspace.escape(container),
|
||||
:query => {'format' => 'json'}
|
||||
)
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
request({
|
||||
:expects => 200,
|
||||
:method => 'HEAD',
|
||||
:path => "#{URI.escape(container)}/#{URI.escape(object)}"
|
||||
:path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
|
||||
}, false)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
request(
|
||||
:expects => [201, 202],
|
||||
:method => 'PUT',
|
||||
:path => URI.escape(name)
|
||||
:path => Fog::Rackspace.escape(name)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ module Fog
|
|||
:expects => 201,
|
||||
:headers => headers,
|
||||
:method => 'PUT',
|
||||
:path => "#{URI.escape(container)}/#{URI.escape(object)}"
|
||||
:path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
|||
# * object<~String> - Name for object
|
||||
#
|
||||
def put_object_manifest(container, object)
|
||||
path = "#{URI.escape(container)}/#{URI.escape(object)}"
|
||||
path = "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
|
||||
request(
|
||||
:expects => 201,
|
||||
:headers => {'X-Object-Manifest' => path},
|
||||
|
|
3
tests/rackspace/url_encoding_tests.rb
Normal file
3
tests/rackspace/url_encoding_tests.rb
Normal 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
|
Loading…
Reference in a new issue