Skip to content

Instantly share code, notes, and snippets.

@ferblape
Created September 20, 2010 06:55
Show Gist options
  • Save ferblape/587513 to your computer and use it in GitHub Desktop.
Save ferblape/587513 to your computer and use it in GitHub Desktop.
# rack-test patch for Ruby 1.9.x
# for multipart forms and UTF-8 characters
module Rack
module Utils
def escape(s)
regexp = case
when RUBY_VERSION >= "1.9" && s.encoding === Encoding.find('UTF-8')
/([^ a-zA-Z0-9_.-\@]+)/u
else
/([^ a-zA-Z0-9_.-\@]+)/n
end
s.to_s.gsub(regexp) {
'%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
}.tr(' ', '+')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment