[前][次][番号順一覧][スレッド一覧]

ruby-changes:29962

From: xibbar <ko1@a...>
Date: Wed, 17 Jul 2013 08:53:02 +0900 (JST)
Subject: [ruby-changes:29962] xibbar:r42014 (trunk): * lib/cgi/util.rb (CGI::Util#escape, unescape): Unuse regexp special

xibbar	2013-07-17 08:52:47 +0900 (Wed, 17 Jul 2013)

  New Revision: 42014

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42014

  Log:
    * lib/cgi/util.rb (CGI::Util#escape, unescape): Unuse regexp special
      global variable. [Feature #8648] Thanks to fotos.

  Modified files:
    trunk/lib/cgi/util.rb

Index: lib/cgi/util.rb
===================================================================
--- lib/cgi/util.rb	(revision 42013)
+++ lib/cgi/util.rb	(revision 42014)
@@ -6,8 +6,8 @@ module CGI::Util https://github.com/ruby/ruby/blob/trunk/lib/cgi/util.rb#L6
   #      # => "%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 https://github.com/ruby/ruby/blob/trunk/lib/cgi/util.rb#L15
   #   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]