Class: String
Constant Summary collapse
- HTML_ESCAPE_MAP =
{ '&' => '&', '>' => '>', '<' => '<', '"' => '"' }
- JS_ESCAPE_MAP =
{ '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" }
Instance Method Summary collapse
- #html_escape ⇒ Object
- #js_escape ⇒ Object
- #json_escape ⇒ Object
-
#marks ⇒ Object
String marks, like :format, :safe.
- #url_escape ⇒ Object
- #url_unescape ⇒ Object
Instance Method Details
#html_escape ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/rad/_support/string.rb', line 7 def html_escape # ERB and Rack both are replacing '/' character, and it's wrong because it destroys links (like '/default/my_item') # ERB::Util.html_escape self # Rack::Utils.escape_html self gsub(/[&"><]/){|special| HTML_ESCAPE_MAP[special]} end |
#js_escape ⇒ Object
34 35 36 |
# File 'lib/rad/_support/string.rb', line 34 def js_escape gsub(/(\\|<\/|\r\n|[\n\r"'])/){JS_ESCAPE_MAP[$1]} end |
#json_escape ⇒ Object
2 3 4 |
# File 'lib/rad/_support/string.rb', line 2 def json_escape ERB::Util.json_escape self end |
#marks ⇒ Object
String marks, like :format, :safe
39 |
# File 'lib/rad/_support/string.rb', line 39 def marks; @marks ||= OpenObject.new end |
#url_escape ⇒ Object
15 16 17 18 |
# File 'lib/rad/_support/string.rb', line 15 def url_escape # TODO2 change to Rack::Utils.escape CGI.escape self end |
#url_unescape ⇒ Object
20 21 22 23 |
# File 'lib/rad/_support/string.rb', line 20 def url_unescape # TODO2 change to Rack::Utils.unescape CGI.unescape self end |