@@ -41,21 +41,12 @@ def initialize(a, b)
4141 end
4242 end
4343
44- def setup
45- unquote ( false )
46- end
47-
48- def teardown
49- unquote ( true )
50- end
51-
5244 def test_hash_encoding
5345 assert_equal %({\" a\" : \" b\" }) , { :a => :b } . to_json
5446 assert_equal %({\" a\" : 1}) , { 'a' => 1 } . to_json
5547 assert_equal %({\" a\" : [1, 2]}) , { 'a' => [ 1 , 2 ] } . to_json
56-
57- sorted_json =
58- '{' + { :a => :b , :c => :d } . to_json [ 1 ..-2 ] . split ( ', ' ) . sort . join ( ', ' ) + '}'
48+
49+ sorted_json = '{' + { :a => :b , :c => :d } . to_json [ 1 ..-2 ] . split ( ', ' ) . sort . join ( ', ' ) + '}'
5950 assert_equal %({\" a\" : \" b\" , \" c\" : \" d\" }) , sorted_json
6051 end
6152
@@ -72,29 +63,14 @@ def test_exception_raised_when_encoding_circular_reference
7263 a << a
7364 assert_raises ( ActiveSupport ::JSON ::CircularReferenceError ) { a . to_json }
7465 end
75-
76- def test_unquote_hash_key_identifiers
66+
67+ def test_hash_key_identifiers_are_always_quoted
7768 values = { 0 => 0 , 1 => 1 , :_ => :_ , "$" => "$" , "a" => "a" , :A => :A , :A0 => :A0 , "A0B" => "A0B" }
7869 assert_equal %w( "$" "A" "A0" "A0B" "_" "a" 0 1 ) , object_keys ( values . to_json )
79- unquote ( true ) { assert_equal %w( $ 0 1 A A0 A0B _ a ) , object_keys ( values . to_json ) }
8070 end
81-
82- def test_unquote_hash_key_identifiers_ignores_javascript_reserved_words
83- values = { "hello" => "world" , "this" => "that" , "with" => "foo" }
84- unquote ( true ) { assert_equal %w( "this" "with" hello ) , object_keys ( values . to_json ) }
85- end
86-
71+
8772 protected
88- def unquote ( value )
89- previous_value = ActiveSupport ::JSON . unquote_hash_key_identifiers
90- ActiveSupport ::JSON . unquote_hash_key_identifiers = value
91- yield if block_given?
92- ensure
93- ActiveSupport ::JSON . unquote_hash_key_identifiers = previous_value if block_given?
94- end
95-
9673 def object_keys ( json_object )
9774 json_object [ 1 ..-2 ] . scan ( /([^{}:,\s ]+):/ ) . flatten . sort
9875 end
99-
10076end
0 commit comments