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

ruby-changes:27092

From: tenderlove <ko1@a...>
Date: Fri, 8 Feb 2013 09:05:09 +0900 (JST)
Subject: [ruby-changes:27092] tenderlove:r39144 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: fixing string quotation

tenderlove	2013-02-08 08:54:29 +0900 (Fri, 08 Feb 2013)

  New Revision: 39144

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

  Log:
    * ext/psych/lib/psych/visitors/yaml_tree.rb: fixing string quotation
      when dumping Ruby strings. Thanks Ingy
    
    * test/psych/test_psych.rb: appropriate tests.
    
    * test/psych/test_yaml.rb: ditto

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/yaml_tree.rb
    trunk/test/psych/test_psych.rb
    trunk/test/psych/test_yaml.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39143)
+++ ChangeLog	(revision 39144)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Feb  8 08:53:27 2013  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/yaml_tree.rb: fixing string quotation
+	  when dumping Ruby strings. Thanks Ingy
+
+	* test/psych/test_psych.rb: appropriate tests.
+
+	* test/psych/test_yaml.rb: ditto
+
 Fri Feb  8 08:50:42 2013  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
Index: ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 39143)
+++ ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 39144)
@@ -253,9 +253,9 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L253
       private :binary?
 
       def visit_String o
-        plain = false
-        quote = false
-        style = Nodes::Scalar::ANY
+        plain = true
+        quote = true
+        style = Nodes::Scalar::PLAIN
         tag   = nil
         str   = o
 
@@ -264,15 +264,14 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L264
           tag   = '!binary' # FIXME: change to below when syck is removed
           #tag   = 'tag:yaml.org,2002:binary'
           style = Nodes::Scalar::LITERAL
+          plain = false
+          quote = false
         elsif o =~ /\n/
-          quote = true
           style = Nodes::Scalar::LITERAL
-        elsif o =~ /^\W/
-          quote = true
-          style = Nodes::Scalar::DOUBLE_QUOTED
         else
-          quote = !(String === @ss.tokenize(o))
-          plain = !quote
+          unless String === @ss.tokenize(o)
+            style = Nodes::Scalar::SINGLE_QUOTED
+          end
         end
 
         ivars = find_ivars o
Index: test/psych/test_psych.rb
===================================================================
--- test/psych/test_psych.rb	(revision 39143)
+++ test/psych/test_psych.rb	(revision 39144)
@@ -20,7 +20,7 @@ class TestPsych < Psych::TestCase https://github.com/ruby/ruby/blob/trunk/test/psych/test_psych.rb#L20
 
   def test_canonical
     yml = Psych.dump({:a => {'b' => 'c'}}, {:canonical => true})
-    assert_match(/\? ! "b/, yml)
+    assert_match(/\? "b/, yml)
   end
 
   def test_header
Index: test/psych/test_yaml.rb
===================================================================
--- test/psych/test_yaml.rb	(revision 39143)
+++ test/psych/test_yaml.rb	(revision 39144)
@@ -1274,7 +1274,16 @@ EOY https://github.com/ruby/ruby/blob/trunk/test/psych/test_yaml.rb#L1274
 
     def test_string_starting_with_non_word_character_uses_double_quotes_without_exclamation_mark
       yaml = Psych.dump("@123'abc")
-      assert_match("\"", yaml)
       refute_match("!", yaml)
     end
+
+    def test_string_dump_with_colon
+      yaml = Psych.dump 'x: foo'
+      refute_match '!', yaml
+    end
+
+    def test_string_dump_starting_with_star
+      yaml = Psych.dump '*foo'
+      refute_match '!', yaml
+    end
 end

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

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