diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-16 19:13:12 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-16 19:13:12 -0800 |
commit | eb029f065c7a30cbba92f0357012ebd9740d3cf8 (patch) | |
tree | 5a7321e59489048552cffab7cffa93edcd4e04ad | |
parent | 9d7be25e66a27d1a4c970921a54b19cb8ce70256 (diff) | |
parent | 066e600b122803d05033b5687e3d5488b312d445 (diff) | |
download | psych-eb029f065c7a30cbba92f0357012ebd9740d3cf8.tar.gz |
Merge pull request #97 from atambo/master
Use literal style when emitting multiline strings, fixes #64
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 7 | ||||
-rw-r--r-- | test/psych/test_yaml.rb | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 9cbc05d..d420abd 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -231,15 +231,18 @@ module Psych 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 diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index 796a44f..cbda385 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -1266,4 +1266,9 @@ EOY 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 |