Issue #8394 has been updated by xibbar (Takeyuki FUJIOKA).

Status changed from Closed to Assigned
Assignee changed from xibbar (Takeyuki FUJIOKA) to seki (Masatoshi Seki)


----------------------------------------
Feature #8394: use String#b instead of dup.force_encoding("ASCII-8BIT")
https://bugs.ruby-lang.org/issues/8394#change-39362

Author: znz (Kazuhiro NISHIYAMA)
Status: Assigned
Priority: Normal
Assignee: seki (Masatoshi Seki)
Category: 
Target version: 


dup.force_encoding("ASCII-8BIT") ???使????????????????? b ???使??????????????????????????????????????????????????????

diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb
index 7de6fc7..bb5df37 100644
--- a/lib/cgi/util.rb
+++ b/lib/cgi/util.rb
@@ -6,7 +6,7 @@ module CGI::Util
   #      # => "%27Stop%21%27+said+Fred"
   def escape(string)
     encoding = string.encoding
-    string.dup.force_encoding('ASCII-8BIT').gsub(/([^ a-zA-Z0-9_.-]+)/) do
+    string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do
       '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
     end.tr(' ', '+').force_encoding(encoding)
   end
diff --git a/lib/erb.rb b/lib/erb.rb
index 51b128e..9cb3999 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -596,7 +596,7 @@ class ERB
     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
       enc = detect_magic_comment(s) || enc
       out = Buffer.new(self, enc)
 
@@ -948,7 +948,7 @@ class ERB
     #   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



-- 
http://bugs.ruby-lang.org/