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

Fixed escaping in Fog::AWS.escape

Now correctly escapes multibyte strings and behaves exactly like
CGI.escape except that the tilde char is not escaped.
This commit is contained in:
croaker 2011-07-12 15:59:51 +02:00
parent a3ed0c4f92
commit 867a352a0f
2 changed files with 6 additions and 2 deletions

View file

@ -46,7 +46,9 @@ module Fog
end
def self.escape(string)
string.gsub( /([^-a-zA-Z0-9_.~]+)/n ) { |match| '%' + match.unpack( 'H2' * match.size ).join( '%' ).upcase }
string.gsub(/([^ a-zA-Z0-9_.\-~]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}.tr(" ", "+")
end
def self.signed_params(params, options = {})

View file

@ -1,3 +1,5 @@
# encoding: utf-8
Shindo.tests('AWS | signed_params', ['aws']) do
returns( Fog::AWS.escape( "'Stop!' said Fred_-~." ) ) { "%27Stop%21%27%20said%20Fred_-~." }
returns( Fog::AWS.escape( "'Stöp!' said Fred_-~." ) ) { "%27St%C3%B6p%21%27+said+Fred_-~." }
end