mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/cgi/util.rb (CGI::Util#escape, unescape): Unuse regexp special
global variable. [Feature #8648] Thanks to fotos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
747b1a3188
commit
fd2fc885b4
1 changed files with 4 additions and 4 deletions
|
@ -6,8 +6,8 @@ module CGI::Util
|
|||
# # => "%27Stop%21%27+said+Fred"
|
||||
def escape(string)
|
||||
encoding = string.encoding
|
||||
string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do
|
||||
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
|
||||
string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
|
||||
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
||||
end.tr(' ', '+').force_encoding(encoding)
|
||||
end
|
||||
|
||||
|
@ -15,8 +15,8 @@ module CGI::Util
|
|||
# string = CGI::unescape("%27Stop%21%27+said+Fred")
|
||||
# # => "'Stop!' said Fred"
|
||||
def unescape(string,encoding=@@accept_charset)
|
||||
str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do
|
||||
[$1.delete('%')].pack('H*')
|
||||
str=string.tr('+', ' ').b.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
|
||||
|
|
Loading…
Reference in a new issue