From e26fe81b0bb395ef60ef2139cd0df16c3a88ce65 Mon Sep 17 00:00:00 2001 From: xibbar Date: Wed, 19 Jun 2013 12:42:05 +0000 Subject: [PATCH] * lib/cgi/util.rb(CGI.escapeHTML): performance improvement. thank you @bbxiao1 via https://github.com/ruby/ruby/pull/333 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/cgi/util.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb index 3fc462df27..61738139fe 100644 --- a/lib/cgi/util.rb +++ b/lib/cgi/util.rb @@ -42,7 +42,8 @@ module CGI::Util # # => "Usage: foo \"bar\" " 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)