Created
September 20, 2010 06:55
-
-
Save ferblape/587513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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