Module: ActiveSupport::JSON::Encoding
- Defined in:
- lib/active_support/json/encoding.rb
Overview
:nodoc:
Defined Under Namespace
Classes: CircularReferenceError, Encoder
Constant Summary collapse
- ESCAPED_CHARS =
- { "\x00" => '\u0000', "\x01" => '\u0001', "\x02" => '\u0002', "\x03" => '\u0003', "\x04" => '\u0004', "\x05" => '\u0005', "\x06" => '\u0006', "\x07" => '\u0007', "\x0B" => '\u000B', "\x0E" => '\u000E', "\x0F" => '\u000F', "\x10" => '\u0010', "\x11" => '\u0011', "\x12" => '\u0012', "\x13" => '\u0013', "\x14" => '\u0014', "\x15" => '\u0015', "\x16" => '\u0016', "\x17" => '\u0017', "\x18" => '\u0018', "\x19" => '\u0019', "\x1A" => '\u001A', "\x1B" => '\u001B', "\x1C" => '\u001C', "\x1D" => '\u001D', "\x1E" => '\u001E', "\x1F" => '\u001F', "\010" => '\b', "\f" => '\f', "\n" => '\n', "\r" => '\r', "\t" => '\t', '"' => '\"', '\\' => '\\\\', '>' => '\u003E', '<' => '\u003C', '&' => '\u0026' } 
Class Attribute Summary collapse
- 
  
    
      .encode_big_decimal_as_string  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    If false, serializes BigDecimal objects as numeric instead of wrapping them in a string. 
- 
  
    
      .escape_html_entities_in_json  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute escape_html_entities_in_json. 
- 
  
    
      .escape_regex  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute escape_regex. 
- 
  
    
      .use_standard_json_time_format  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    If true, use ISO 8601 format for dates and times. 
Class Method Summary collapse
Class Attribute Details
.encode_big_decimal_as_string ⇒ Object
If false, serializes BigDecimal objects as numeric instead of wrapping them in a string.
| 116 117 118 | # File 'lib/active_support/json/encoding.rb', line 116 def encode_big_decimal_as_string @encode_big_decimal_as_string end | 
.escape_html_entities_in_json ⇒ Object
Returns the value of attribute escape_html_entities_in_json.
| 119 120 121 | # File 'lib/active_support/json/encoding.rb', line 119 def escape_html_entities_in_json @escape_html_entities_in_json end | 
.escape_regex ⇒ Object
Returns the value of attribute escape_regex.
| 118 119 120 | # File 'lib/active_support/json/encoding.rb', line 118 def escape_regex @escape_regex end | 
.use_standard_json_time_format ⇒ Object
If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
| 112 113 114 | # File 'lib/active_support/json/encoding.rb', line 112 def use_standard_json_time_format @use_standard_json_time_format end | 
Class Method Details
.escape(string) ⇒ Object
| 130 131 132 133 134 135 136 | # File 'lib/active_support/json/encoding.rb', line 130 def escape(string) string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY) json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] } json = %("#{json}") json.force_encoding(::Encoding::UTF_8) json end |