Permalink
Browse files

Merge pull request #97 from atambo/master

Use literal style when emitting multiline strings, fixes #64
  • Loading branch information...
2 parents 9d7be25 + 066e600 commit eb029f065c7a30cbba92f0357012ebd9740d3cf8 @tenderlove tenderlove committed Nov 17, 2012
Showing with 10 additions and 2 deletions.
  1. +5 −2 lib/psych/visitors/yaml_tree.rb
  2. +5 −0 test/psych/test_yaml.rb
@@ -231,15 +231,18 @@ def visit_String o
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
@@ -1266,4 +1266,9 @@ def test_normal_exit
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

0 comments on commit eb029f0

Please sign in to comment.