Class: CGI

Inherits:
Object show all
Defined in:
lib/extensions/rhocgi/cgi.rb

Constant Summary collapse

TABLE_FOR_ESCAPE_HTML__ =
{
  '&' => '&',
  '"' => '"',
  '<' => '&lt;',
  '>' => '&gt;',
}

Class Method Summary collapse

Class Method Details

.escapeHTML(string) ⇒ Object

Escape special characters in HTML, namely &"<>

CGI::escapeHTML('Usage: foo "bar" <baz>')
   # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"


12
13
14
# File 'lib/extensions/rhocgi/cgi.rb', line 12

def CGI::escapeHTML(string)
  string.gsub(/[&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
end