This project is archived and is in readonly mode.
[Patch] JSON.generate raises exception in v3.0.2 + json_pure => '~>1.4.3'
-
Ken Mayer
Patch file with test & fix...
-
Ken Mayer
- No changes were found…
-
Ken Mayer
- Tag changed from activesupport, json, rails3.0.2 to activesupport, json, patched, rails3.0.2
-
Ken Mayer
From f52f3295196d48015c1bd5f337a5978e14c3acd6 Mon Sep 17 00:00:00 2001 From: Kenneth Mayer <kmayer@bitwrangler.com> Date: Thu, 2 Dec 2010 09:11:08 -0800 Subject: [PATCH] bug: JSON::Pure reuses a State object for options Fixes [#6047 state:resolved] An earlier commit (33b95) tries to merging encoding options (active_support/json/encoding.rb:#options_for) would raise a method_missing error -- but only if you were using json_pure. This converts State objects back to an options hash via :to_h --- activesupport/lib/active_support/json/encoding.rb | 4 ++-- activesupport/test/json/encoding_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index c8cac52..e8d14b3 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -36,8 +36,8 @@ module ActiveSupport class Encoder attr_reader :options - def initialize(options = nil) - @options = options + def initialize(options_or_state = nil) + @options = options_or_state.respond_to?(:to_h) ? options_or_state.to_h : options_or_state @seen = [] end diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index e0494de..622eca2 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -125,6 +125,11 @@ class TestJSONEncoding < Test::Unit::TestCase a[:sub] << a assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) } end + + def test_no_exception_raised_with_json_pure + require 'json/pure/generator' + assert_equal "[]", JSON::Pure::Generator::State.new.generate([]) + end def test_hash_key_identifiers_are_always_quoted values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"} -- 1.7.2.2 -
Ken Mayer
- Title changed from JSON.generate raises exception in v3.0.2 + json_pure => '~>1.4.3' to [Patch] JSON.generate raises exception in v3.0.2 + json_pure => '~>1.4.3'
-
Ken Mayer
- Tag changed from activesupport, json, patched, rails3.0.2 to activesupport, json, patched
-
dvdplm
Confirmed in rails 3.0.3
-
Josh Kalderimis
- Tag changed from activesupport, json, patched to activesupport, json
Hi Ken,
I have tried replicating this issue but don't see any errors like you mention.
I am pretty sure that this is more of a json_pure issue than a rails issue.
For example
bundle exec rails runner 'JSON.generate([0])'is not testing how active support helps generate json, it is only running the generate json_pure method within a rails environment.
Also, your test is not testing rails at all but only json_pure.
Have you tried updating your json_pure version?
Thanks,
Josh
