summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-11-16 19:13:12 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-11-16 19:13:12 -0800
commiteb029f065c7a30cbba92f0357012ebd9740d3cf8 (patch)
tree5a7321e59489048552cffab7cffa93edcd4e04ad
parent9d7be25e66a27d1a4c970921a54b19cb8ce70256 (diff)
parent066e600b122803d05033b5687e3d5488b312d445 (diff)
downloadpsych-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.rb7
-rw-r--r--test/psych/test_yaml.rb5
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