End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CGI::Util#escape_html
escape_html(string)
lib/cgi/util.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/cgi/util.rb, line 74
def escapeHTML(string)
enc = string.encoding
unless enc.ascii_compatible?
if enc.dummy?
origenc = enc
enc = Encoding::Converter.asciicompat_encoding(enc)
string = enc ? string.encode(enc) : string.b
end
table = Hash[TABLE_FOR_ESCAPE_HTML__.map {|pair|pair.map {|s|s.encode(enc)}}]
string = string.gsub(/#{"['&\"<>]".encode(enc)}/, table)
string.encode!(origenc) if origenc
string
else
string = string.b
string.gsub!(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
string.force_encoding(enc)
end
end
Alias of #escapeHTML
Synonym for CGI.escapeHTML(str)
See also
#escapeHTML
#escapeElement
#escape_element
#escapeURIComponent
also in
3.4 · 3.3 · 3.1 · 3.0