Bug #8612 » ruby_2_0_0_cgi_escape_issue.patch
lib/cgi/util.rb | ||
---|---|---|
# # => "%27Stop%21%27+said+Fred"
|
||
def CGI::escape(string)
|
||
encoding = string.encoding
|
||
string.dup.force_encoding('ASCII-8BIT').gsub(/([^ a-zA-Z0-9_.-]+)/) do
|
||
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
|
||
string.dup.force_encoding('ASCII-8BIT').gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
|
||
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
||
end.tr(' ', '+').force_encoding(encoding)
|
||
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
|
- « Previous
- 1
- 2
- 3
- 4
- Next »