ruby-changes:30771
From: tenderlove <ko1@a...>
Date: Fri, 6 Sep 2013 02:39:59 +0900 (JST)
Subject: [ruby-changes:30771] tenderlove:r42850 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
tenderlove 2013-09-06 02:39:53 +0900 (Fri, 06 Sep 2013) New Revision: 42850 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42850 Log: * ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when strings start with special characters. [Fixes GH-157] https://github.com/tenderlove/psych/issues/157 * test/psych/test_string.rb: test for change. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/test_string.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42849) +++ ChangeLog (revision 42850) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Sep 6 02:37:22 2013 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when + strings start with special characters. + [Fixes GH-157] https://github.com/tenderlove/psych/issues/157 + + * test/psych/test_string.rb: test for change. + Fri Sep 6 00:05:14 2013 Nobuyoshi Nakada <nobu@r...> * class.c (rewrite_cref_stack): remove recursion. Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 42849) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 42850) @@ -288,6 +288,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L288 quote = false elsif o =~ /\n/ style = Nodes::Scalar::LITERAL + elsif o =~ /^\W/ + style = Nodes::Scalar::DOUBLE_QUOTED else unless String === @ss.tokenize(o) style = Nodes::Scalar::SINGLE_QUOTED Index: test/psych/test_string.rb =================================================================== --- test/psych/test_string.rb (revision 42849) +++ test/psych/test_string.rb (revision 42850) @@ -15,6 +15,11 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_string.rb#L15 end end + def test_doublequotes_when_there_is_a_single + yaml = Psych.dump "@123'abc" + assert_match(/---\s*"/, yaml) + end + def test_dash_dot assert_cycle '-.' assert_cycle '+.' -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/