From 1c836f811c7f7e2cd29e2bab68f0780e10bb0767 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Thu, 7 Feb 2013 23:54:29 +0000 Subject: * 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/lib/psych/visitors/yaml_tree.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'ext/psych') diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index 53cbad3e10..6b6a5ffa19 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -253,9 +253,9 @@ module Psych 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 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 -- cgit v1.2.3