Sha256: 3cc85d958fbdd014549ce8f7f8b1c9fc72c138a8728a16a8b312b5f89db8a2f3
Contents?: true
Size: 957 Bytes
Versions: 12
Compression:
Stored size: 957 Bytes
Contents
class String def json_escape ERB::Util.json_escape self end HTML_ESCAPE_MAP = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' } 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 def url_escape # TODO2 change to Rack::Utils.escape CGI.escape self end def url_unescape # TODO2 change to Rack::Utils.unescape CGI.unescape self end JS_ESCAPE_MAP = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" } def js_escape gsub(/(\\|<\/|\r\n|[\n\r"'])/){JS_ESCAPE_MAP[$1]} end # String marks, like :format, :safe def marks; @marks ||= OpenObject.new end end
Version data entries
12 entries across 12 versions & 1 rubygems