[rackspace] fix excluding extra characters in Rackspace.escape

This commit is contained in:
Sami Samhuri 2013-08-19 16:21:56 -07:00
parent bf7d348d88
commit f651d05654
2 changed files with 7 additions and 2 deletions

View File

@ -130,7 +130,10 @@ module Fog
# 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
# '-' is a special character inside a regex class so it must be first or last.
# Add extra excludes before the final '-' so it always remains trailing, otherwise
# an unwanted range is created by mistake.
str.gsub(/([^a-zA-Z0-9_.#{extra_exclude_chars}-]+)/) do
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
end
end

View File

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