<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -209,19 +209,19 @@ class RenderTest &lt; Test::Unit::TestCase
 
   def test_do_with_render_json
     get :render_json_hello_world
-    assert_equal '{hello: &quot;world&quot;}', @response.body
+    assert_equal '{&quot;hello&quot;: &quot;world&quot;}', @response.body
     assert_equal 'application/json', @response.content_type
   end
 
   def test_do_with_render_json_with_callback
     get :render_json_hello_world_with_callback
-    assert_equal 'alert({hello: &quot;world&quot;})', @response.body
+    assert_equal 'alert({&quot;hello&quot;: &quot;world&quot;})', @response.body
     assert_equal 'application/json', @response.content_type
   end
 
   def test_do_with_render_symbol_json
     get :render_symbol_json
-    assert_equal '{hello: &quot;world&quot;}', @response.body
+    assert_equal '{&quot;hello&quot;: &quot;world&quot;}', @response.body
     assert_equal 'application/json', @response.content_type
   end
 </diff>
      <filename>actionpack/test/controller/render_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,9 +8,6 @@ require 'fixtures/comment'
 
 class JsonSerializationTest &lt; Test::Unit::TestCase
   def setup
-    # Quote all keys (so that we can test against strictly valid JSON).
-    ActiveSupport::JSON.unquote_hash_key_identifiers = false
-
     @contact = Contact.new(
       :name        =&gt; 'Konata Izumi',
       :age         =&gt; 16,
@@ -70,8 +67,6 @@ class DatabaseConnectedJsonEncodingTest &lt; Test::Unit::TestCase
   fixtures :authors, :posts, :comments, :tags, :taggings
 
   def setup
-    ActiveSupport::JSON.unquote_hash_key_identifiers = false
-
     @david = authors(:david)
   end
 </diff>
      <filename>activerecord/test/json_serialization_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,7 @@
 *2.0.0 [Preview Release]* (September 29th, 2007)
 
+* Fixed JSON encoding to use quoted keys according to the JSON standard #8762 [choonkat/chuyeow]
+
 * Alias Object#send to send! for Ruby 1.9 forward compatibility.  [Jeremy Kemper]
 
 * Backport Object#instance_variable_defined? for Ruby &lt; 1.8.6.  [Jeremy Kemper]</diff>
      <filename>activesupport/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -2,8 +2,6 @@ class Hash
   def to_json #:nodoc:
     returning result = '{' do
       result &lt;&lt; map do |key, value|
-        key = ActiveSupport::JSON::Variable.new(key.to_s) if 
-          ActiveSupport::JSON.can_unquote_identifier?(key)
         &quot;#{ActiveSupport::JSON.encode(key)}: #{ActiveSupport::JSON.encode(value)}&quot;
       end * ', '
       result &lt;&lt; '}'</diff>
      <filename>activesupport/lib/active_support/json/encoders/hash.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,13 +10,6 @@ end
 
 module ActiveSupport
   module JSON
-    # When +true+, Hash#to_json will omit quoting string or symbol keys
-    # if the keys are valid JavaScript identifiers.  Note that this is
-    # technically improper JSON (all object keys must be quoted), so if
-    # you need strict JSON compliance, set this option to +false+.
-    mattr_accessor :unquote_hash_key_identifiers
-    @@unquote_hash_key_identifiers = true
-
     class CircularReferenceError &lt; StandardError
     end
 
@@ -30,11 +23,6 @@ module ActiveSupport
         end
       end
 
-      def can_unquote_identifier?(key) #:nodoc:
-        unquote_hash_key_identifiers &amp;&amp; 
-          ActiveSupport::JSON.valid_identifier?(key)
-      end
-
       protected
         def raise_on_circular_reference(value) #:nodoc:
           stack = Thread.current[REFERENCE_STACK_VARIABLE] ||= []</diff>
      <filename>activesupport/lib/active_support/json/encoding.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 module ActiveSupport
   module JSON
-    # A string that returns itself as as its JSON-encoded form.
+    # A string that returns itself as its JSON-encoded form.
     class Variable &lt; String
       def to_json
         self</diff>
      <filename>activesupport/lib/active_support/json/variable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -41,21 +41,12 @@ class TestJSONEncoding &lt; Test::Unit::TestCase
     end
   end
 
-  def setup
-    unquote(false)
-  end
-  
-  def teardown
-    unquote(true)
-  end
-  
   def test_hash_encoding
     assert_equal %({\&quot;a\&quot;: \&quot;b\&quot;}), { :a =&gt; :b }.to_json
     assert_equal %({\&quot;a\&quot;: 1}), { 'a' =&gt; 1  }.to_json
     assert_equal %({\&quot;a\&quot;: [1, 2]}), { 'a' =&gt; [1,2] }.to_json
-    
-    sorted_json  = 
-      '{' + {:a =&gt; :b, :c =&gt; :d}.to_json[1..-2].split(', ').sort.join(', ') + '}'
+
+    sorted_json = '{' + {:a =&gt; :b, :c =&gt; :d}.to_json[1..-2].split(', ').sort.join(', ') + '}'
     assert_equal %({\&quot;a\&quot;: \&quot;b\&quot;, \&quot;c\&quot;: \&quot;d\&quot;}), sorted_json
   end
 
@@ -72,29 +63,14 @@ class TestJSONEncoding &lt; Test::Unit::TestCase
     a &lt;&lt; a
     assert_raises(ActiveSupport::JSON::CircularReferenceError) { a.to_json }
   end
-  
-  def test_unquote_hash_key_identifiers
+
+  def test_hash_key_identifiers_are_always_quoted
     values = {0 =&gt; 0, 1 =&gt; 1, :_ =&gt; :_, &quot;$&quot; =&gt; &quot;$&quot;, &quot;a&quot; =&gt; &quot;a&quot;, :A =&gt; :A, :A0 =&gt; :A0, &quot;A0B&quot; =&gt; &quot;A0B&quot;}
     assert_equal %w( &quot;$&quot; &quot;A&quot; &quot;A0&quot; &quot;A0B&quot; &quot;_&quot; &quot;a&quot; 0 1 ), object_keys(values.to_json)
-    unquote(true) { assert_equal %w( $ 0 1 A A0 A0B _ a ), object_keys(values.to_json) }
   end
-  
-  def test_unquote_hash_key_identifiers_ignores_javascript_reserved_words
-    values = {&quot;hello&quot; =&gt; &quot;world&quot;, &quot;this&quot; =&gt; &quot;that&quot;, &quot;with&quot; =&gt; &quot;foo&quot;}
-    unquote(true) { assert_equal %w( &quot;this&quot; &quot;with&quot; hello ), object_keys(values.to_json) }
-  end
-  
+
   protected
-    def unquote(value)
-      previous_value = ActiveSupport::JSON.unquote_hash_key_identifiers
-      ActiveSupport::JSON.unquote_hash_key_identifiers = value
-      yield if block_given?
-    ensure
-      ActiveSupport::JSON.unquote_hash_key_identifiers = previous_value if block_given?
-    end
-    
     def object_keys(json_object)
       json_object[1..-2].scan(/([^{}:,\s]+):/).flatten.sort
     end
-    
 end</diff>
      <filename>activesupport/test/json/encoding_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>66d05f5e2c7ac6b18220956fbcf34efcd32638fc</id>
    </parent>
  </parents>
  <author>
    <name>David Heinemeier Hansson</name>
    <email>david@loudthinking.com</email>
  </author>
  <url>http://github.com/rubyruy/rails/commit/7275d2749cb829d89bffe7e6aa87c99084351f6a</url>
  <id>7275d2749cb829d89bffe7e6aa87c99084351f6a</id>
  <committed-date>2007-09-30T13:57:50-07:00</committed-date>
  <authored-date>2007-09-30T13:57:50-07:00</authored-date>
  <message>Fixed JSON encoding to use quoted keys according to the JSON standard (closes #8762) [choonkat/chuyeow]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7697 5ecf4fe2-1ee6-0310-87b1-e25e094e27de</message>
  <tree>ea1ffa76f30699cb84827bf6d21dbdb6d1201c1e</tree>
  <committer>
    <name>David Heinemeier Hansson</name>
    <email>david@loudthinking.com</email>
  </committer>
</commit>
