Created
May 14, 2011 02:33
-
-
Save AquaGeek/971731 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #6047
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment