ruby-changes:29379
From: xibbar <ko1@a...>
Date: Wed, 19 Jun 2013 21:42:16 +0900 (JST)
Subject: [ruby-changes:29379] xibbar:r41431 (trunk): * lib/cgi/util.rb(CGI.escapeHTML): performance improvement.
xibbar 2013-06-19 21:42:05 +0900 (Wed, 19 Jun 2013) New Revision: 41431 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41431 Log: * lib/cgi/util.rb(CGI.escapeHTML): performance improvement. thank you @bbxiao1 via https://github.com/ruby/ruby/pull/333 Modified files: trunk/lib/cgi/util.rb Index: lib/cgi/util.rb =================================================================== --- lib/cgi/util.rb (revision 41430) +++ lib/cgi/util.rb (revision 41431) @@ -42,7 +42,8 @@ module CGI::Util https://github.com/ruby/ruby/blob/trunk/lib/cgi/util.rb#L42 # # => "Usage: foo \"bar\" <baz>" def unescapeHTML(string) enc = string.encoding - if [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(enc) + return string unless string.include? '&' + 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) when 'apos' then "'".encode(enc) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/