Module: ActiveSupport::JSON::Encoding
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Defined in: | activesupport/lib/active_support/json/encoding.rb |
Constant Summary
-
ESCAPED_CHARS =
# File 'activesupport/lib/active_support/json/encoding.rb', line 74{ U2028 => -'\u2028'.b, U2029 => -'\u2029'.b, ">".b => -'\u003e'.b, "<".b => -'\u003c'.b, "&".b => -'\u0026'.b, }.freeze -
FULL_ESCAPE_REGEX =
# File 'activesupport/lib/active_support/json/encoding.rb', line 83Regexp.union(*ESCAPED_CHARS.keys).freeze
-
HTML_ENTITIES_REGEX =
# File 'activesupport/lib/active_support/json/encoding.rb', line 82Regexp.union(*(ESCAPED_CHARS.keys - [U2028, U2029])).freeze
-
JS_SEPARATORS_REGEX =
# File 'activesupport/lib/active_support/json/encoding.rb', line 84Regexp.union(U2028, U2029).freeze
-
TR_ESCAPE_SUPPORTED =
# File 'activesupport/lib/active_support/json/encoding.rb', line 96Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("4.1.0")
-
U2028 =
# File 'activesupport/lib/active_support/json/encoding.rb', line 71-"\u2028".b
-
U2029 =
# File 'activesupport/lib/active_support/json/encoding.rb', line 72-"\u2029".b
-
UTF8_ESCAPED_CHARS =
# File 'activesupport/lib/active_support/json/encoding.rb', line 86{ "\u2028" => '\u2028', "\u2029" => '\u2029', ">" => '\u003e', "<" => '\u003c', "&" => '\u0026', }.freeze -
UTF8_HTML_ENTITIES =
# File 'activesupport/lib/active_support/json/encoding.rb', line 93UTF8_ESCAPED_CHARS.except("\u2028", "\u2029").freeze
-
UTF8_JS_SEPARATORS =
# File 'activesupport/lib/active_support/json/encoding.rb', line 94UTF8_ESCAPED_CHARS.slice("\u2028", "\u2029").freeze
Class Attribute Summary
-
.escape_html_entities_in_json
rw
If true, encode >, <, & as escaped unicode sequences (e.g.
-
.escape_js_separators_in_json
rw
If true, encode LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) as escaped unicode sequences ('\u2028' and '\u2029').
-
.json_encoder
rw
Sets the encoder used by Rails to encode Ruby objects into
::ActiveSupport::JSONstrings inObject#to_jsonand encode. - .json_encoder=(encoder) rw
-
.time_precision
rw
Sets the precision of encoded time values.
-
.use_standard_json_time_format
rw
If true, use ISO 8601 format for dates and times.
Class Method Summary
Class Attribute Details
.escape_html_entities_in_json (rw)
If true, encode >, <, & as escaped unicode sequences (e.g. > as \u003e) as a safety measure.
# File 'activesupport/lib/active_support/json/encoding.rb', line 285
attr_accessor :escape_html_entities_in_json
.escape_js_separators_in_json (rw)
If true, encode LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) as escaped unicode sequences ('\u2028' and '\u2029'). Historically these characters were not valid inside JavaScript strings but that changed in ECMAScript 2019. As such it's no longer a concern in modern browsers: https://caniuse.com/mdn-javascript_builtins_json_json_superset.
# File 'activesupport/lib/active_support/json/encoding.rb', line 292
attr_accessor :escape_js_separators_in_json
.json_encoder (rw)
Sets the encoder used by Rails to encode Ruby objects into ::ActiveSupport::JSON strings
in Object#to_json and ActiveSupport::JSON.encode.
# File 'activesupport/lib/active_support/json/encoding.rb', line 300
attr_reader :json_encoder
.json_encoder=(encoder) (rw)
[ GitHub ]# File 'activesupport/lib/active_support/json/encoding.rb', line 302
def json_encoder=(encoder) @json_encoder = encoder @encoder_without_options = encoder.new.freeze @encoder_without_escape = encoder.new(escape: false).freeze end
.time_precision (rw)
Sets the precision of encoded time values. Defaults to 3 (equivalent to millisecond precision)
# File 'activesupport/lib/active_support/json/encoding.rb', line 296
attr_accessor :time_precision
.use_standard_json_time_format (rw)
If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
# File 'activesupport/lib/active_support/json/encoding.rb', line 281
attr_accessor :use_standard_json_time_format
Class Method Details
.encode_without_escape(value)
[ GitHub ]# File 'activesupport/lib/active_support/json/encoding.rb', line 312
def encode_without_escape(value) # :nodoc: @encoder_without_escape.encode(value) end
.encode_without_options(value)
[ GitHub ]# File 'activesupport/lib/active_support/json/encoding.rb', line 308
def (value) # :nodoc: @encoder_without_options.encode(value) end