Module: Formular::HtmlEscape
- Included in:
- Element::Modules::Error, Element::Modules::EscapeValue, Element::Modules::Hint, Element::Modules::Label, Element::OptGroup, Element::Select
- Defined in:
- lib/formular/html_escape.rb
Constant Summary collapse
- HTML_ESCAPE =
see activesupport/lib/active_support/core_ext/string/output_safety.rb
{ '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' }
- HTML_ESCAPE_REGEXP =
/[&"'><]/
- HTML_ESCAPE_ONCE_REGEXP =
/["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]+));)/
Instance Method Summary collapse
-
#html_escape(string) ⇒ Object
A utility method for escaping HTML tag characters.
-
#html_escape_once(string) ⇒ Object
A utility method for escaping HTML without affecting existing escaped entities.
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 |