Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use literal style when emitting multiline strings, fixes #64 #97

Merged
merged 1 commit into from
Nov 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/psych/visitors/yaml_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,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
Expand Down
5 changes: 5 additions & 0 deletions test/psych/test_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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