diff options
author | Alex Tambellini <atambellini@gmail.com> | 2012-10-27 19:16:01 -0400 |
---|---|---|
committer | Alex Tambellini <atambellini@gmail.com> | 2012-10-28 21:16:21 -0400 |
commit | 066e600b122803d05033b5687e3d5488b312d445 (patch) | |
tree | 332b019ebc63563c90dcf992daebed08ee6b408b | |
parent | 851de5c2310d4e2dd38e95b678be1f08e2fdb4da (diff) | |
download | psych-066e600b122803d05033b5687e3d5488b312d445.tar.gz |
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 948a976..5cb5850 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -230,15 +230,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 807c058..496f1a4 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 |