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

ruby-changes:26316

From: tenderlove <ko1@a...>
Date: Fri, 14 Dec 2012 07:47:57 +0900 (JST)
Subject: [ruby-changes:26316] tenderlove:r38367 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: quote strings that begin

tenderlove	2012-12-14 07:45:16 +0900 (Fri, 14 Dec 2012)

  New Revision: 38367

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

  Log:
    * ext/psych/lib/psych/visitors/yaml_tree.rb: quote strings that begin
      with non-word characters.  Thanks Alex Tambellini!
    * test/psych/test_yaml.rb: appropriate test case

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38366)
+++ ChangeLog	(revision 38367)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec 14 07:43:44 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/yaml_tree.rb: quote strings that begin
+	  with non-word characters.  Thanks Alex Tambellini!
+	* test/psych/test_yaml.rb: appropriate test case
+
 Thu Dec 13 23:14:17 2012  Shugo Maeda  <shugo@r...>
 
 	* vm_insnhelper.c (vm_call_super_method): a workaround for the
Index: ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 38366)
+++ ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 38367)
@@ -242,6 +242,9 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L242
         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
Index: test/psych/test_yaml.rb
===================================================================
--- test/psych/test_yaml.rb	(revision 38366)
+++ test/psych/test_yaml.rb	(revision 38367)
@@ -1271,4 +1271,10 @@ EOY https://github.com/ruby/ruby/blob/trunk/test/psych/test_yaml.rb#L1271
       yaml = Psych.dump("multi\nline\nstring")
       assert_match("|", yaml)
     end
+
+    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
 end

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

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