Module: Formular::HtmlEscape

Constant Summary collapse

HTML_ESCAPE =

see activesupport/lib/active_support/core_ext/string/output_safety.rb

{ '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
HTML_ESCAPE_REGEXP =
/[&"'><]/
HTML_ESCAPE_ONCE_REGEXP =
/["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]+));)/

Instance Method Summary collapse

Instance Method Details

#html_escape(string) ⇒ Object

A utility method for escaping HTML tag characters.



10
11
12
# File 'lib/formular/html_escape.rb', line 10

def html_escape(string)
  string.to_s.gsub(HTML_ESCAPE_REGEXP, HTML_ESCAPE)
end

#html_escape_once(string) ⇒ Object

A utility method for escaping HTML without affecting existing escaped entities.



15
16
17
# File 'lib/formular/html_escape.rb', line 15

def html_escape_once(string)
  string.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
end