summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-19 12:42:05 +0000
committerxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-19 12:42:05 +0000
commite26fe81b0bb395ef60ef2139cd0df16c3a88ce65 (patch)
treebb552b8e64f4a782682cd4227d655b568f2f35bc /lib
parente82f5f7ddb19811c40af9d7214a338c954b03fa7 (diff)
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/cgi/util.rb3
1 files changed, 2 insertions, 1 deletions
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\" <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)