[前][次][番号順一覧][スレッド一覧]

ruby-changes:18564

From: tenderlove <ko1@a...>
Date: Tue, 18 Jan 2011 02:51:51 +0900 (JST)
Subject: [ruby-changes:18564] Ruby:r30587 (trunk): * ext/psych/lib/psych/visitors/json_tree.rb (visit_String): JSON

tenderlove	2011-01-18 02:48:09 +0900 (Tue, 18 Jan 2011)

  New Revision: 30587

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30587

  Log:
    * ext/psych/lib/psych/visitors/json_tree.rb (visit_String): JSON
      strings should be dumped with double quotes. [ruby-core:34186]
    * test/psych/test_json_tree.rb: test for double quotes

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/json_tree.rb
    trunk/test/psych/test_json_tree.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30586)
+++ ChangeLog	(revision 30587)
@@ -1,3 +1,10 @@
+Tue Jan 18 02:46:55 2011  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/json_tree.rb (visit_String): JSON
+	  strings should be dumped with double quotes. [ruby-core:34186]
+
+	* test/psych/test_json_tree.rb: test for double quotes
+
 Mon Jan 17 23:36:33 2011  Tanaka Akira  <akr@f...>
 
 	* array.c (rb_ary_times): less MEMCPY calls.
Index: ext/psych/lib/psych/visitors/json_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/json_tree.rb	(revision 30586)
+++ ext/psych/lib/psych/visitors/json_tree.rb	(revision 30587)
@@ -6,7 +6,7 @@
       end
 
       def visit_String o
-        @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::ANY
+        @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
       end
       alias :visit_Symbol :visit_String
     end
Index: test/psych/test_json_tree.rb
===================================================================
--- test/psych/test_json_tree.rb	(revision 30586)
+++ test/psych/test_json_tree.rb	(revision 30587)
@@ -3,11 +3,11 @@
 module Psych
   class TestJSONTree < TestCase
     def test_string
-      assert_match(/(['"])foo\1/, Psych.to_json("foo"))
+      assert_match(/"foo"/, Psych.to_json("foo"))
     end
 
     def test_symbol
-      assert_match(/(['"])foo\1/, Psych.to_json(:foo))
+      assert_match(/"foo"/, Psych.to_json(:foo))
     end
 
     def test_nil
@@ -36,8 +36,8 @@
       json = Psych.to_json(list)
       assert_match(/]$/, json)
       assert_match(/^\[/, json)
-      assert_match(/['"]one['"]/, json)
-      assert_match(/['"]two['"]/, json)
+      assert_match(/"one"/, json)
+      assert_match(/"two"/, json)
     end
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]