Project

General

Profile

Actions

Feature #8394

closed

use String#b instead of dup.force_encoding("ASCII-8BIT")

Added by znz (Kazuhiro NISHIYAMA) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
-
[ruby-dev:47336]

Description

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

Updated by xibbar (Takeyuki FUJIOKA) over 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to xibbar (Takeyuki FUJIOKA)

私はいいと思うので、確認してコミットしようと思います。
終わったら担当者を関さんに振ります。

Actions #2

Updated by xibbar (Takeyuki FUJIOKA) over 11 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40786.
Kazuhiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/cgi/util.rb: Use String#b instead of dup.force_encoding("ASCII-8BIT")
    [Feature #8394]

Updated by xibbar (Takeyuki FUJIOKA) over 11 years ago

  • Status changed from Closed to Assigned
  • Assignee changed from xibbar (Takeyuki FUJIOKA) to seki (Masatoshi Seki)
Actions #4

Updated by zzak (zzak _) over 11 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r41030.
Kazuhiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0