Sha256: a568f0466f22d2fc8fa0374b8a82d027cb99b912490b57eb6082d67593f48c8f
Contents?: true
Size: 668 Bytes
Versions: 26
Compression:
Stored size: 668 Bytes
Contents
# http://jfire.io/blog/2012/04/30/how-to-securely-bootstrap-json-in-a-rails-view/ class ActionView::Base JSON_ESCAPE_MAP = { "/" => '\/' } if "ruby".encoding_aware? JSON_ESCAPE_MAP["\342\200\250".force_encoding('UTF-8').encode!] = '
' JSON_ESCAPE_MAP["\342\200\251".force_encoding('UTF-8').encode!] = '
' else JSON_ESCAPE_MAP["\342\200\250"] = '
' JSON_ESCAPE_MAP["\342\200\251"] = '
' end def escape_json(json) if json result = json.gsub(/(\/|\342\200\250|\342\200\251)/u) { |match| JSON_ESCAPE_MAP[match] } json.html_safe? ? result.html_safe : result else '' end end end
Version data entries
26 entries across 26 versions & 1 rubygems