ruby-changes:29403
From: xibbar <ko1@a...>
Date: Thu, 20 Jun 2013 06:12:08 +0900 (JST)
Subject: [ruby-changes:29403] xibbar:r41455 (trunk): * lib/cgi/util.rb (CGI.escapeHTML): performance improvement.
xibbar 2013-06-20 06:11:52 +0900 (Thu, 20 Jun 2013) New Revision: 41455 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41455 Log: * lib/cgi/util.rb (CGI.escapeHTML): performance improvement. thank you nagachika-san. Modified files: trunk/lib/cgi/util.rb Index: lib/cgi/util.rb =================================================================== --- lib/cgi/util.rb (revision 41454) +++ lib/cgi/util.rb (revision 41455) @@ -41,8 +41,8 @@ module CGI::Util https://github.com/ruby/ruby/blob/trunk/lib/cgi/util.rb#L41 # CGI::unescapeHTML("Usage: foo "bar" <baz>") # # => "Usage: foo \"bar\" <baz>" def unescapeHTML(string) - enc = string.encoding return string unless string.include? '&' + enc = string.encoding if enc != Encoding::UTF_8 && [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(enc) return string.gsub(Regexp.new('&(apos|amp|quot|gt|lt|#[0-9]+|#x[0-9A-Fa-f]+);'.encode(enc))) do case $1.encode(Encoding::US_ASCII) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/