summaryrefslogtreecommitdiff
path: root/lib/cgi/util.rb
diff options
context:
space:
mode:
authorxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-16 23:52:47 +0000
committerxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-16 23:52:47 +0000
commitfd2fc885b43283aa3d76820b2dfa9de19a77012f (patch)
tree8c267ae667d897190dfea6221c3a329048eb8abd /lib/cgi/util.rb
parent747b1a3188125a93be49d8cdd1781f768c191ba8 (diff)
* 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
Diffstat (limited to 'lib/cgi/util.rb')
-rw-r--r--lib/cgi/util.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb
index 71fe48abd13..199e17bbbc3 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