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

Merged
merged 1 commit into from Nov 17, 2012

2 participants

@atambo

See #64 for details.

@atambo

This commit changes the emitted yaml from:

--- ! 'multi

  line

  string'

to:

--- ! |-
  multi
  line
  string

I'm still not sure why the exclamation mark shows up. @tenderlove, do you have any idea how to remove that exclamation mark?

@tenderlove
Owner

I think we need to invert the quote and plain flags to get rid of the !. Can you try this patch?

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
@atambo

Your patch worked. I updated the pull request. Thanks @tenderlove

@tenderlove tenderlove merged commit eb029f0 into tenderlove:master Nov 17, 2012

1 check passed

Details default The Travis build passed
@rkoster rkoster referenced this pull request in cloudfoundry-incubator/bosh-workspace Feb 21, 2014
Closed

Unable to use multi line string in meta #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment