1. 03 12月, 2013 1 次提交
  2. 01 12月, 2013 1 次提交
  3. 27 11月, 2013 3 次提交
    • G
      Make the JSON encoder pluggable · d4ef6c00
      Godfrey Chan 提交于
      d4ef6c00
    • G
      Removed the Ruby encoder and switched to using the JSON gem · 80e75520
      Godfrey Chan 提交于
      Got all the tests passing again.
      
      Support for `encode_json` has been removed (and consequently the
      ability to encode `BigDecimal`s as numbers, as mentioned in the
      previous commit). Install the `activesupport-json_encoder` gem
      to get it back.
      80e75520
    • G
      Removed support for encoding BigDecimal as a JSON number · 4d02296c
      Godfrey Chan 提交于
      This is because the new encoder will no longer support encode_json.
      Therefore our only choice is to return `to_i` or `to_s` in
      `BigDecimal#as_json`. Since casting a BigDecimal to an integer is
      most likely a lossy operation, we chose to encode it as a string.
      
      Support for encoding BigDecimal as a string will return via the
      `activesupport-json_encoder` gem.
      4d02296c
  4. 07 11月, 2013 3 次提交
  5. 31 10月, 2013 2 次提交
    • R
      Require time before monkey-patching it · e3d775f0
      Robin Dupret 提交于
      Same as #12710 but for the time module this time. This time it should
      fix the Active Model test suite in isolation avoiding a TypeError to
      be raised about the superclass of the DateTime object.
      e3d775f0
    • R
      Require bigdecimal before monkey-patching it · 9d6d07dd
      Robin Dupret 提交于
      If we try to monkey-patch the class before requiring it, then a
      "superclass mismatch" (TypeError) error is raised and the build can't
      run correctly.
      
      Fixes #12708
      9d6d07dd
  6. 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
  7. 01 6月, 2013 1 次提交
  8. 11 5月, 2013 1 次提交
  9. 09 5月, 2013 1 次提交
    • M
      Added escaping of U+2028 and U+2029 inside the json encoder. · 582b4417
      Mario Caropreso 提交于
      U+2028 and U+2029 are allowed inside strings in JSON (as all literal
      Unicode characters) but JavaScript defines them as newline
      seperators. Because no literal newlines are allowed in a string, this
      causes a ParseError in the browser. We work around this issue by
      replacing them with the escaped version. The resulting JSON is still
      valid and can be parsed in the browser.
      
      This commit has been coauthored with Viktor Kelemen @yikulju
      582b4417
  10. 03 4月, 2013 1 次提交
    • Z
      Escape multibyte line terminators in JSON encoding · 9b8ee8e0
      zackham 提交于
      Currently, json/encoding respects the JSON spec (as it should) which 
      disallows \n and \r inside strings, escaping them as expected.
      
      Unfortunately, ECMA-262 (Javascript) disallows not only \n and \r in 
      strings, but "Line Terminators" which includes U+2028 and U+2029. 
      See here: http://bclary.com/2004/11/07/#a-7.3
      
      This pull request adds U+2028 and U+2029 to be escaped.
      
      # Why? 
      
      It's very common to see something like this in a Rails template:
      
      <script type="text/javascript"> 
      var posts = <%= @posts.to_json %>;
      </script>
      
      If U+2028 or U+2029 are part of any attributes output in the to_json
      call, you will end up with an exception.
      In Chrome: Uncaught SyntaxError: Unexpected token ILLEGAL 
      
      # Why not?
      
      This is JSON encoding, and the JSON spec is specific about how to 
      encode strings. U+2028 and U+2029 don't get special treatment.
      
      Just trying to start a discussion... what do you do in your apps
      to deal with this? Is there a convention I'm missing?
      9b8ee8e0
  11. 25 2月, 2013 1 次提交
  12. 07 1月, 2013 2 次提交
  13. 15 12月, 2012 1 次提交
    • B
      Remove unicode character encoding from ActiveSupport::JSON.encode · 8f8397e0
      Brett Carter 提交于
      The encoding scheme (e.g.  -> "\u2620") was broken for characters
      not in the Basic Multilingual Plane.  It is possible to escape them
      for json using the weird encoding scheme of a twelve-character
      sequence representing the UTF-16 surrogate pair (e.g. '𠜎' ->
      "\u270e\u263a") but this wasn't properly handled in the escaping code.
      Since raw UTF-8 is allowed in json, it was decided to simply pass
      through the raw bytes rather than attempt to escape them.
      8f8397e0
  14. 12 11月, 2012 1 次提交
  15. 15 9月, 2012 1 次提交
  16. 08 8月, 2012 1 次提交
  17. 22 7月, 2012 1 次提交
  18. 31 5月, 2012 2 次提交
  19. 30 5月, 2012 1 次提交
  20. 28 5月, 2012 1 次提交
  21. 14 5月, 2012 1 次提交
  22. 02 5月, 2012 1 次提交
  23. 01 5月, 2012 1 次提交
  24. 09 2月, 2012 1 次提交
  25. 13 1月, 2012 1 次提交
  26. 06 1月, 2012 1 次提交
  27. 02 1月, 2012 1 次提交
  28. 25 12月, 2011 1 次提交
  29. 01 12月, 2011 1 次提交
  30. 24 11月, 2011 1 次提交
    • J
      Implement ArraySerializer and move old serialization API to a new namespace. · 8896b4fd
      José Valim 提交于
      The following constants were renamed:
      
        ActiveModel::Serialization     => ActiveModel::Serializable
        ActiveModel::Serializers::JSON => ActiveModel::Serializable::JSON
        ActiveModel::Serializers::Xml  => ActiveModel::Serializable::XML
      
      The main motivation for such a change is that `ActiveModel::Serializers::JSON`
      was not actually a serializer, but a module that when included allows the target to be serializable to JSON.
      
      With such changes, we were able to clean up the namespace to add true serializers as the ArraySerializer.
      8896b4fd
  31. 30 9月, 2011 1 次提交
  32. 15 8月, 2011 1 次提交
  33. 26 5月, 2011 1 次提交