diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/cgi/util.rb | 2 | ||||
-rw-r--r-- | lib/erb.rb | 4 |
3 files changed, 7 insertions, 3 deletions
@@ -1,3 +1,7 @@ +Sun Jun 2 15:04:35 2013 Zachary Scott <[email protected]> + + * lib/cgi/util.rb, lib/erb.rb: Use String#b [Feature #8394] by znz + Sun Jun 2 14:10:21 2013 Zachary Scott <[email protected]> * lib/irb/lc/help-message: Apply english updates for irb --help #7510 diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb index 98ff4be0ca..3fc462df27 100644 --- a/lib/cgi/util.rb +++ b/lib/cgi/util.rb @@ -15,7 +15,7 @@ module CGI::Util # 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) diff --git a/lib/erb.rb b/lib/erb.rb index 51b128e3c5..510eae9a1e 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 # see String#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 |