Commit Graph

76 Commits

Author SHA1 Message Date
Rafael Mendonça França
a59d661a82 Fix test to ruby 2.0
The default enconding changed on Ruby 2.0
2013-05-10 13:36:42 -03:00
Rafael Mendonça França
c910388587 Revert "Remove unicode character encoding from ActiveSupport::JSON.encode"
This reverts commit 815a9431ab.

Conflicts:
	activesupport/test/json/encoding_test.rb

Reason: This was causing a regression where the resulting string is always
returning UTF-8. Also it changes the behavior of this method on a stable release.

Fixes #9498.
2013-05-08 21:03:37 -03:00
Carlos Antonio da Silva
df048b574b Use 1.8 style hash in json encoding test 2012-12-14 23:33:53 -02:00
Brett Carter
815a9431ab Remove unicode character encoding from ActiveSupport::JSON.encode
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.

Backport of 9ace3a8820

Conflicts:

	activesupport/CHANGELOG.md
	activesupport/lib/active_support/json/encoding.rb
	activesupport/test/json/encoding_test.rb
2012-12-14 20:09:56 -05:00
Carlos Antonio da Silva
25b23d7ecc Fix json encoding test with ruby 1.8.7 and random hash order
Introduced in 3e53fe6.
2012-11-13 09:17:48 -02:00
Yves Senn
be79632b96 backport #8185, #as_json isolates options when encoding a hash.
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.

Conflicts:

	activesupport/CHANGELOG.md
2012-11-13 08:44:47 +01:00
Rafael Mendonça França
af65b8c9e7 Revert "Deprecate ActiveSupport::JSON::Variable"
This reverts commit bcfa013399.
2012-08-01 15:56:38 -03:00
Erich Menge
bcfa013399 Deprecate ActiveSupport::JSON::Variable 2012-05-30 14:32:24 -05:00
Erich Menge
624f801d27 True, False, and Nil should be represented in as_json as themselves.
Conflicts:

	activesupport/lib/active_support/json/encoding.rb
	activesupport/test/json/encoding_test.rb
2012-05-30 10:24:23 -05:00
Arun Agrawal
ec7457ed2a Removing extra requires from the test. Already loaded in abstract_unit. 2011-07-31 23:36:21 +05:30
Xavier Noria
d352e0dff2 checked all .rb files in the project tree for missing magic comments, one was missing
Came with this one-liner for this:

    find . -name '*.rb' | \
    xargs chardet | \
    grep -v ascii | \
    cut -d: -f1 -s | \
    xargs -n1 ruby -0777 -ne 'puts $FILENAME if $_ !~ /#.*coding:\s*utf/i'

Welcome $_.
2011-07-23 14:50:29 +02:00
José Valim
a761d77902 Merge pull request #248 from bigfix/enumerable_as_json
Enumerable should pass encoding options to children in #as_json/#to_json
2011-05-07 03:19:56 -07:00
Josh Kalderimis
1d8be7bc6f AS Json parse_error makes a return for backwards compatibility, although it will return MultiJson::DecodeError 2011-04-19 00:01:50 +02:00
Josh Kalderimis
e019587e31 removed AS backends and instead rely on MultiJson for json decoding 2011-04-18 21:39:15 +02:00
John Firebaugh
080e2a7abf Enumerable should pass encoding options to children in #as_json/#to_json. 2011-04-01 12:16:54 -07:00
Diego Carrion
a1edbf7206 parse dates to yaml in json arrays
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-22 21:09:54 -03:00
Diego Carrion
7004434ad8 test json decoding with time parsing disabled with all backends and respect ActiveSupport.parse_json_times when converting to yaml
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-22 21:09:54 -03:00
Josh Kalderimis
e8c870726a Updated the json date regex to recognize xmlschema formatted date times during json decoding. [#3031 state:resolved]
Signed-off-by: Santiago Pastorino and Emilio Tagua <santiago+emilioe@wyeworks.com>
2011-02-12 13:30:30 -02:00
Josh Kalderimis
b17d8d727f Fixes an issue when decoding a json string which looks like a date but is invalid. This DateTime parse error is now caught and the original string is instead passed back [#6286 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-02-11 13:54:57 -02:00
Santiago Pastorino
434aa09560 Fix tests providing valid JSON 2011-02-02 20:53:03 -02:00
Maxime RETY
68e3fb8109 Fix JSON decoding of newline character with Yaml backend [#3479 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-02-02 18:57:48 -02:00
Aaron Patterson
370bcd1a01 use ! " " YAML string literal syntax rather than removing both quotes 2011-01-21 14:09:59 -08:00
Aaron Patterson
d780d1f508 ordering can change depending on ruby version, so parse the JSON and verify data structure equality 2011-01-17 16:06:55 -08:00
Alexey Nayden
d2c17dbd11 Complex struct encoding test
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-01-15 00:06:17 -02:00
Josh Kalderimis
199e220e88 Fixed various isolated test missing requires within AS.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-01-12 12:37:28 -02:00
Jakub Suder
2524cf404c fixed some issues with JSON encoding
- 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>
2010-09-07 11:33:10 -07:00
Santiago Pastorino
e1d4e78b15 Removes unused vars
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-24 01:19:44 +02:00
Santiago Pastorino
cb321546b7 Time has it own implementation of xmlschema, now AMo doesn't depend on TZInfo
[#4979 state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-02 01:51:03 +02:00
Xavier Noria
5d7d0c2fa3 BigDecimal#as_json does not really specify the F format, it delegates that to whatever BigDecimal#to_s default format is, do the same in its test 2010-05-03 22:11:33 +02:00
Cezary Baginski
1067a7be52 Fix BigDecimal JSON encoding test. [#4495 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-28 09:02:03 -07:00
Jeremy Kemper
c1d7327071 JSON: encode objects that don't have a native JSON representation using to_hash, if available, instead of instance_values (the old fallback) or to_s (other encoders' default). Encode BigDecimal and Regexp encode as strings to conform with other encoders. Try to transcode non-UTF-8 strings. 2010-04-26 19:55:39 -07:00
Yehuda Katz
a3eaaf6b50 Fix a JSON ordering issue 2010-02-10 14:46:16 -08:00
Jeremy Kemper
63bb955a99 Automatically prefer Yajl or JSON backend over Yaml, if available 2010-02-05 10:22:45 -08:00
Brian Lopez
a96bf4ab5e Add yajl-ruby as a JSON parsing backend
[#2666 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-02-05 10:15:51 -08:00
Dwayne Litzenberger
808cad2bb4 Fix ActiveSupport::JSON encoding of control characters [\x00-\x1f]
According to RFC 4627, only the following Unicode code points are
allowed unescaped in JSON:

  unescaped = %x20-21 / %x23-5B / %x5D-10FFFF

However, ActiveSupport::JSON did not escape the range %x00-1f.  This caused
parse errors when trying to decode the resulting output.

[#3345 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-12-23 11:46:06 -08:00
Jeremy Kemper
bc1538e995 Repair time dependencies 2009-11-14 11:37:06 -08:00
Jeremy Kemper
053a0f6ac4 Clean up spurious JSON decoding test failure 2009-09-13 05:43:02 -07:00
Daniel Sheppard
b3381cacaf Fix that JSON parser fails to read escaped backslashes.
[#973 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-08-09 22:30:44 -07:00
Bas Van Klinkenberg
0fbeaa98e4 Fixed a bug in JSON decoding with Yaml backend, where a combination of dates, escaped or unicode encoded data and arrays would make the parser fail with a ParseError exception. [#2831 state:resolved]
Signed-off-by: Yehuda Katz <wycats@gmail.com>
2009-08-08 12:44:41 -03:00
Jeremy Kemper
49824e8ad6 JSON.escape returns UTF-8 strings
[#2849 state:resolved]
2009-07-01 16:22:19 -07:00
Jeremy Kemper
00ee990443 JSON: split encoding and coercion 2009-06-08 13:21:30 -07:00
rick
e89241c92f load the JSON Backend lazily. If the JSON gem is already loaded, use the JSONGem backend by default. 2009-05-17 19:18:00 -07:00
Jeremy Kemper
3bd32754e2 Privatize rails_to_json 2009-04-26 15:54:28 -07:00
rick
3c4c6bd0df * Add pluggable JSON backends with support for the JSON gem. [rick]
Example: ActiveSupport::JSON.backend = "JSONGem"

  All internal Rails JSON encoding is now handled by ActiveSupport::JSON.encode().  Use of #to_json is not recommended, as it may clash with other libraries that overwrite it.  However, you can recover Rails specific functionality
  if you really want to use #to_json.

    gem 'json'
    ActiveSupport::JSON.backend = "JSONGem"

    class ActiveRecord::Base
      alias to_json rails_to_json
    end
2009-04-23 00:08:40 -07:00
Jeremy Kemper
6fee981fa4 Opt in to JSON 2009-04-22 16:48:58 -07:00
Jeremy Kemper
42a06d2d62 stdlib autoloads were hanging on 1.9.1 2009-04-22 09:10:48 -07:00
Jeremy Kemper
7bcfff4457 Explicit test dependencies 2009-03-28 23:56:14 -07:00
Ubiratan Pires Alberton
7b382cb9e5 Reverted affe50105f and added more JSON decoding tests.
Works on Ruby 1.8 and 1.9

[#1100 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-03-11 14:36:14 -07:00
Tim Pope
9b9b2937ce Properly decode \u escape sequences in JSON [#1100 state:resolved] [Tim Pope, Philip Hallstrom]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2009-03-10 17:05:17 +00:00
Jeremy Kemper
1c36172c13 Ruby 1.9 compat: rename deprecated assert_raises to assert_raise.
[#1617 state:resolved]
2009-03-08 13:11:58 -07:00