1. 23 12月, 2016 1 次提交
  2. 13 11月, 2016 3 次提交
  3. 30 10月, 2016 1 次提交
    • P
      Fix an issue with JSON encoding of "Infinity" and "NaN" values · 8776f15b
      Prathamesh Sonpatki 提交于
      - When `as_json` returns `Infinity` or `NaN` as the value of any of the key,
        we don't used to call `as_json` on it as it was treated as primitive.
      - This used to pass `Infinity` or `NaN` to `JSON.generate` and Ruby used
        to throw an error for `Infinity/NaN not allowed in JSON.`
      - This patch changes the code to call `as_json` on these primitives so
        that they are converted to proper values before being passed to
        `JSON.generate`.
      - Fixes #26877.
      8776f15b
  4. 29 10月, 2016 1 次提交
  5. 16 8月, 2016 1 次提交
  6. 07 8月, 2016 3 次提交
  7. 23 7月, 2016 1 次提交
  8. 09 4月, 2016 1 次提交
  9. 12 7月, 2015 1 次提交
  10. 17 6月, 2015 1 次提交
  11. 03 3月, 2015 1 次提交
  12. 03 2月, 2015 1 次提交
  13. 04 1月, 2015 2 次提交
  14. 30 10月, 2014 1 次提交
  15. 22 6月, 2014 1 次提交
  16. 18 6月, 2014 1 次提交
  17. 15 3月, 2014 1 次提交
  18. 27 1月, 2014 3 次提交
  19. 03 12月, 2013 1 次提交
  20. 27 11月, 2013 5 次提交
  21. 23 11月, 2013 1 次提交
  22. 15 11月, 2013 1 次提交
    • G
      Improved compatibility with the stdlib JSON gem. · 0f33d70e
      Godfrey Chan 提交于
      Previously, calling `::JSON.{generate,dump}` sometimes causes
      unexpected failures such as intridea/multi_json#86.
      
      `::JSON.{generate,dump}` now bypasses the ActiveSupport JSON encoder
      completely and yields the same result with or without ActiveSupport.
      This means that it will **not** call `as_json` and will ignore any
      options that the JSON gem does not natively understand. To invoke
      ActiveSupport's JSON encoder instead, use `obj.to_json(options)` or
      `ActiveSupport::JSON.encode(obj, options)`.
      0f33d70e
  23. 07 11月, 2013 2 次提交
  24. 06 11月, 2013 2 次提交
    • G
      Eliminate `JSON.{parse,load,generate,dump}` and `def to_json` · ff1192fe
      Godfrey Chan 提交于
      JSON.{dump,generate} offered by the JSON gem is not compatiable with
      Rails at the moment and can cause a lot of subtle bugs when passed
      certain data structures. This changed all direct usage of the JSON gem
      in internal Rails code to always go through AS::JSON.{decode,encode}.
      
      We also shouldn't be implementing `to_json` most of the time, and
      these occurances are replaced with an equivilent `as_json`
      implementation to avoid problems down the road.
      
      See [1] for all the juicy details.
      
      [1]: intridea/multi_json#138 (comment)
      ff1192fe
    • G
      Fixed Object#as_json and Struct#as_json with options · 134c1156
      Godfrey Chan 提交于
      These methods now takes the same options as Hash#as_json, for example:
      
          struct = Struct.new(:foo, :bar).new
          struct.foo = "hello"
          struct.bar = "world"
          json = struct.as_json(only: [:foo]) # => {foo: "hello"}
      
      This is extracted from PR #11728 from @sergiocampama, see also the
      discussion in #11460.
      134c1156
  25. 13 9月, 2013 1 次提交
    • G
      Moved all JSON core extensions into core_ext/object/json · 64c88fb5
      Godfrey Chan 提交于
      TL;DR The primary driver is to remove autoload surprise.
      
      This is related to #12106. (The root cause for that ticket is that
      json/add defines Regexp#to_json among others, but here I'll reproduce
      the problem without json/add.)
      
      Before:
      
         >> require 'active_support/core_ext/to_json'
         => true
         >> //.as_json
         NoMethodError: undefined method `as_json' for //:Regexp
           from (irb):3
           from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>'
         >> //.to_json
         => "\"(?-mix:)\""
         >> //.as_json
         => "(?-mix:)"
      
      After:
      
         >> require 'active_support/core_ext/to_json'
         => true
         >> //.as_json
         => "(?-mix:)"
      
      This is because ActiveSupport::JSON is autoloaded the first time
      Object#to_json is called, which causes additional core extentions
      (previously defined in active_support/json/encoding.rb) to be loaded.
      
      When someone require 'active_support/core_ext', the expectation is
      that it would add certain methods to the core classes NOW. The
      previous behaviour causes additional methods to be loaded the first
      time you call `to_json`, which could cause nasty surprises and other
      unplesant side-effects.
      
      This change moves all core extensions in to core_ext/json. AS::JSON is
      still autoloaded on first #to_json call, but since it nolonger
      include the core extensions, it should address the aforementioned bug.
      
      *Requiring core_ext/object/to_json now causes a deprecation warnning*
      64c88fb5
  26. 01 6月, 2013 1 次提交
  27. 26 5月, 2013 1 次提交