Bug #8612 » ruby_1_9_3_cgi_escape_issue.patch
lib/cgi/util.rb | ||
---|---|---|
# url_encoded_string = CGI::escape("'Stop!' said Fred")
|
||
# # => "%27Stop%21%27+said+Fred"
|
||
def CGI::escape(string)
|
||
string.gsub(/([^ a-zA-Z0-9_.-]+)/) do
|
||
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
|
||
string.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
|
||
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
||
end.tr(' ', '+')
|
||
end
|
||
... | ... | |
# string = CGI::unescape("%27Stop%21%27+said+Fred")
|
||
# # => "'Stop!' said Fred"
|
||
def CGI::unescape(string,encoding=@@accept_charset)
|
||
str=string.tr('+', ' ').force_encoding(Encoding::ASCII_8BIT).gsub(/((?:%[0-9a-fA-F]{2})+)/) do
|
||
[$1.delete('%')].pack('H*')
|
||
str=string.tr('+', ' ').force_encoding(Encoding::ASCII_8BIT).gsub(/((?:%[0-9a-fA-F]{2})+)/) do |m|
|
||
[m.delete('%')].pack('H*')
|
||
end.force_encoding(encoding)
|
||
str.valid_encoding? ? str : str.force_encoding(string.encoding)
|
||
end
|