Sha256: 67890a5790084f73c6e0dedd11e4dcf47ee15f3e89c937c35efba1623c898453
Contents?: true
Size: 750 Bytes
Versions: 9
Compression:
Stored size: 750 Bytes
Contents
# encoding: utf-8 module Apiary module Helpers module JavascriptHelper JS_ESCAPE_MAP = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" } JS_ESCAPE_MAP["\342\200\250".force_encoding(Encoding::UTF_8).encode!] = '
' JS_ESCAPE_MAP["\342\200\251".force_encoding(Encoding::UTF_8).encode!] = '
' def escape_javascript(javascript) if javascript javascript.gsub(/(\\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u) {|match| JS_ESCAPE_MAP[match] } else '' end end alias_method :j, :escape_javascript end end end
Version data entries
9 entries across 9 versions & 1 rubygems