aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json/encoding_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix behavior of JSON encoding for Exceptionnamusyaka2016-04-091-0/+5
|
* Add tests to ensure we don't interfere with json gem's outputGodfrey Chan2015-07-111-102/+32
|
* Escape HTML entities in JSON keysRafael Mendonça França2015-06-161-0/+7
| | | | Fixes CVE-2015-3226
* Skip the failing tests on Rubinius for nowRobin Dupret2015-03-021-0/+2
|
* Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | onwards.
* Remove deprecated ActiveSupport::JSON::Encoding::CircularReferenceError.Rafael Mendonça França2015-01-041-24/+0
|
* Remove deprecated ActiveSupport::JSON::Encoding.encode_big_decimal_as_string=Rafael Mendonça França2015-01-041-16/+0
|
* Remove redundant `to_s` in interpolationclaudiob2014-10-301-1/+1
|
* Avoid hardcoded magic number in test teardown.Zuhao Wan2014-06-221-14/+19
|
* Extract out with_env_tz helper method.Zuhao Wan2014-06-181-7/+3
| | | | | It’s used at so many places that extracting it out into a helper file is worth doing.
* Fix #to_json for BasicObject EnumerablesSammy Larbi2014-03-141-10/+33
|
* Add support for JSON time_precision to Time and DateTimeAndrew White2014-01-261-1/+19
|
* Rename subsecond_fraction_digits option to time_precisionAndrew White2014-01-261-3/+3
|
* Consolidate JSON encoding tests in one fileAndrew White2014-01-261-11/+48
|
* Added back the `encode_big_decimal_as_string` option with warningGodfrey Chan2013-12-021-0/+16
| | | | | Also added the missing CHANGELOG entry for #12183 @ 80e7552073 and 4d02296cfb.
* Be explicit and use the actual unicode sequenceGodfrey Chan2013-11-261-1/+1
|
* Removed the Ruby encoder and switched to using the JSON gemGodfrey Chan2013-11-261-2/+2
| | | | | | | | | 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.
* Removed support for encoding BigDecimal as a JSON numberGodfrey Chan2013-11-261-11/+0
| | | | | | | | | | 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.
* Expanded coverage on JSON encodingGodfrey Chan2013-11-261-2/+12
|
* Added some failing tests where the JSON encoder is not resolving as_json ↵Godfrey Chan2013-11-261-2/+12
| | | | correctly
* When Array#as_json and Hash#as_json are called without options, theyGodfrey Chan2013-11-221-0/+16
| | | | | should also call #as_json on the children without options (instead of nil)
* Improved compatibility with the stdlib JSON gem.Godfrey Chan2013-11-141-0/+45
| | | | | | | | | | | | 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)`.
* Standardize all JSON encoded times to use 3 decimal fractional secondsRyan Glover2013-11-071-3/+3
|
* Do not expose internal state in the public encoder API (i.e. as_json)Godfrey Chan2013-11-061-3/+9
| | | | | | | | | | | | | | | See [1] for why this is not a good idea. As part of this refactor, circular reference protection in as_json has been removed and the corresponding error class has been deprecated. As discussed with @jeremy, circular reference error is considered programmer errors and protecting against it is out of scope for the encoder. This is again based on the excellent work by @sergiocampama in #11728. [1]: https://github.com/intridea/multi_json/pull/138#issuecomment-24468223
* Eliminate `JSON.{parse,load,generate,dump}` and `def to_json`Godfrey Chan2013-11-051-4/+4
| | | | | | | | | | | | | | | 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)
* Fixed Object#as_json and Struct#as_json with optionsGodfrey Chan2013-11-051-2/+27
| | | | | | | | | | | | 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.
* Moved all JSON core extensions into core_ext/object/jsonGodfrey Chan2013-09-131-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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*
* Remove active_support/json/variable was deprecated.kennyj2013-06-011-7/+0
|
* Fix some typo in method names, variablesVipul A M2013-05-261-1/+1
|
* Added escaping of U+2028 and U+2029 inside the json encoder.Mario Caropreso2013-05-091-2/+2
| | | | | | | | | | | 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
* Fixed bad tests to clean up after themselves.Ryan Davis2013-05-031-4/+11
|
* rewrite order dependent test case. #8185Yves Senn2012-12-271-1/+2
| | | | | | As reported (https://github.com/rails/rails/pull/8185#issuecomment-11702226) this test relied on the order a hash was serialized. Comparing the parsed hash makes the test no longer order dependent.
* Remove unicode character encoding from ActiveSupport::JSON.encodeBrett Carter2012-12-141-3/+16
| | | | | | | | | | 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.
* `#as_json` isolates options when encoding a hash. Closes #8182Yves Senn2012-11-121-0/+18
| | | | | | Setting options in a custom `#as_json` method had side effects. Modifications of the `options` hash leaked outside and influenced the conversion of other objects contained in the hash.
* Deprecate ActiveSupport::JSON::VariableErich Menge2012-08-071-0/+7
| | | | | | | | | | Reason: ActiveSupport::JSON::Variable is not used anymore internally. It was deprecated in 3-2-stable but we reverted all the deprecation for point releases. See #6536 and #6546. Conflicts: activesupport/lib/active_support/json/variable.rb
* Remove deprecated ActiveSupport::JSON::Variable.Erich Menge2012-05-301-2/+0
|
* True, False, and Nil should be represented in as_json as themselves.Erich Menge2012-05-291-0/+6
|
* BigDecimal string wrapping in JSON serialization can now be opted-out, fixes ↵David FRANCOIS2012-05-021-0/+11
| | | | #6033
* JSON: encode BigDecimal NaN/Infinity as null.Sebi Burkhard2012-05-011-0/+1
|
* Merge pull request #2532 from ↵Piotr Sarnacki2012-04-301-0/+3
|\ | | | | | | | | hasclass/as_json__encode_infinite_and_nan_floats_as_null JSON: Encode infinite or NaN floats as `null` to generate valid JSON.
| * JSON: Encode infinite or NaN floats as null to generate valid JSON.Sebi Burkhard2011-08-151-0/+3
| |
* | use AS::TestCase as the base classAaron Patterson2012-01-051-1/+1
| |
* | use #to_s to convert Range to jsonSergey Nartimov2012-01-011-0/+4
| |
* | remove checks for encodings availabilitySergey Nartimov2011-12-251-2/+2
| |
* | Initial pass at removing dead 1.8.x code from Active Support.José Valim2011-12-201-17/+13
|/ | | | | | There are a bunch of other implicit branches that adds 1.8.x specific code that still needs to be removed. Pull requests for those cases are welcome.
* Enumerable should pass encoding options to children in #as_json/#to_json.John Firebaugh2011-04-011-9/+24
|
* ordering can change depending on ruby version, so parse the JSON and verify ↵Aaron Patterson2011-01-171-3/+10
| | | | data structure equality
* Complex struct encoding testAlexey Nayden2011-01-151-0/+23
| | | | Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Fixed various isolated test missing requires within AS.Josh Kalderimis2011-01-121-0/+1
| | | | Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* fixed some issues with JSON encodingJakub Suder2010-09-071-1/+64
| | | | | | | | | | | - as_json in ActiveModel should return a hash and handle :only/:except/:methods options - Array and Hash should call as_json on their elements - json methods should not modify options argument [#5374 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>