From fd2fc885b43283aa3d76820b2dfa9de19a77012f Mon Sep 17 00:00:00 2001 From: xibbar Date: Tue, 16 Jul 2013 23:52:47 +0000 Subject: [PATCH] * 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 --- lib/cgi/util.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb index 71fe48abd1..199e17bbbc 100644 --- a/lib/cgi/util.rb +++ b/lib/cgi/util.rb @@ -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