ruby-changes:25641
From: tenderlove <ko1@a...>
Date: Sat, 17 Nov 2012 12:16:04 +0900 (JST)
Subject: [ruby-changes:25641] tenderlove:r37698 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: use literal YAML style
tenderlove 2012-11-17 12:15:54 +0900 (Sat, 17 Nov 2012) New Revision: 37698 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37698 Log: * ext/psych/lib/psych/visitors/yaml_tree.rb: use literal YAML style when emitting multi-line strings. Thanks @atambo * test/psych/test_yaml.rb: test for change. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/test_yaml.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 37697) +++ ChangeLog (revision 37698) @@ -1,3 +1,10 @@ +Sat Nov 17 12:14:50 2012 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/visitors/yaml_tree.rb: use literal YAML style + when emitting multi-line strings. Thanks @atambo + + * test/psych/test_yaml.rb: test for change. + Sat Nov 17 12:03:41 2012 Aaron Patterson <aaron@t...> * ext/psych/lib/psych/scalar_scanner.rb: avoid raising exceptions when Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 37697) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 37698) @@ -231,15 +231,18 @@ plain = false quote = false style = Nodes::Scalar::ANY + tag = nil + str = o if binary?(o) str = [o].pack('m').chomp tag = '!binary' # FIXME: change to below when syck is removed #tag = 'tag:yaml.org,2002:binary' style = Nodes::Scalar::LITERAL + elsif o =~ /\n/ + quote = true + style = Nodes::Scalar::LITERAL else - str = o - tag = nil quote = !(String === @ss.tokenize(o)) plain = !quote end Index: test/psych/test_yaml.rb =================================================================== --- test/psych/test_yaml.rb (revision 37697) +++ test/psych/test_yaml.rb (revision 37698) @@ -1266,4 +1266,9 @@ Psych.load("2000-01-01 00:00:00.#{"0"*1000} +00:00\n") # '[ruby-core:13735]' end + + def test_multiline_string_uses_literal_style + yaml = Psych.dump("multi\nline\nstring") + assert_match("|", yaml) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/