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

ruby-changes:28978

From: zzak <ko1@a...>
Date: Sun, 2 Jun 2013 15:06:12 +0900 (JST)
Subject: [ruby-changes:28978] zzak:r41030 (trunk): * lib/cgi/util.rb, lib/erb.rb: Use String#b [Feature #8394] by znz

zzak	2013-06-02 15:06:00 +0900 (Sun, 02 Jun 2013)

  New Revision: 41030

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

  Log:
    * lib/cgi/util.rb, lib/erb.rb: Use String#b [Feature #8394] by znz

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41029)
+++ ChangeLog	(revision 41030)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun  2 15:04:35 2013  Zachary Scott  <zachary@z...>
+
+	* lib/cgi/util.rb, lib/erb.rb: Use String#b [Feature #8394] by znz
+
 Sun Jun  2 14:10:21 2013  Zachary Scott  <zachary@z...>
 
 	* lib/irb/lc/help-message: Apply english updates for irb --help #7510
Index: lib/cgi/util.rb
===================================================================
--- lib/cgi/util.rb	(revision 41029)
+++ lib/cgi/util.rb	(revision 41030)
@@ -15,7 +15,7 @@ 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('+', ' ').force_encoding(Encoding::ASCII_8BIT).gsub(/((?:%[0-9a-fA-F]{2})+)/) do
+    str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do
       [$1.delete('%')].pack('H*')
     end.force_encoding(encoding)
     str.valid_encoding? ? str : str.force_encoding(string.encoding)
Index: lib/erb.rb
===================================================================
--- lib/erb.rb	(revision 41029)
+++ lib/erb.rb	(revision 41030)
@@ -596,7 +596,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L596
     def compile(s)
       enc = s.encoding
       raise ArgumentError, "#{enc} is not ASCII compatible" if enc.dummy?
-      s = s.dup.force_encoding("ASCII-8BIT") # don't use constant Enoding::ASCII_8BIT for miniruby
+      s = s.b # see String#b
       enc = detect_magic_comment(s) || enc
       out = Buffer.new(self, enc)
 
@@ -948,7 +948,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L948
     #   Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
     #
     def url_encode(s)
-      s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.]/n) {
+      s.to_s.b.gsub(/[^a-zA-Z0-9_\-.]/n) {
         sprintf("%%%02X", $&.unpack("C")[0])
       }
     end

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

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