lib/active_support/json/encoding.rb in activesupport-7.2.2 vs lib/active_support/json/encoding.rb in activesupport-8.0.0.beta1
- old
+ new
@@ -34,17 +34,17 @@
end
# Encode the given object into a JSON string
def encode(value)
unless options.empty?
- value = value.as_json(options.dup)
+ value = value.as_json(options.dup.freeze)
end
json = stringify(jsonify(value))
# Rails does more escaping than the JSON gem natively does (we
# escape \u2028 and \u2029 and optionally >, <, & to work around
# certain browser problems).
- if Encoding.escape_html_entities_in_json
+ if @options.fetch(:escape_html_entities, Encoding.escape_html_entities_in_json)
json.gsub!(">", '\u003e')
json.gsub!("<", '\u003c')
json.gsub!("&", '\u0026')
end
json.gsub!("\u2028", '\u2028')