Module: Sinatra::Helpers::Escape::HTML
Overview
Constant Summary collapse
- ESCAPE_HTML =
Map special characters to HTML entities.
{ '&' .freeze => '&', '<' .freeze => '<', '>' .freeze => '>', # '\'' .freeze => ''', '\'' .freeze => ''', '"' .freeze => '"', }
- ESCAPE_HTML_PATTERN =
Regexp search pattern for special characters.
::Regexp.union( *ESCAPE_HTML.keys )
Instance Method Summary collapse
-
#h(str) ⇒ String
Escapes the string so it’s safe to use in HTML.
Instance Method Details
#h(str) ⇒ String
Escapes the string so it’s safe to use in HTML.
40 41 42 43 |
# File 'lib/sinatra-helpers/escape/html.rb', line 40 def h( str ) #::Rack::Utils.escape_html( str ) str.to_s.gsub( ESCAPE_HTML_PATTERN ){ |c| ESCAPE_HTML[c] } end |