Bug #1311: YAML::dump creates strings YAML::load cannot parse
http://redmine.ruby-lang.org/issues/show/1311

Author: Noah Easterly
Status: Open, Priority: Normal
ruby -v: ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.9.0], ruby 1.8.7 (2008-05-31 patchlevel 0) [i686-darwin9.3.0]

This case seems to occur whenever
* the string begins with a newline, and 
* the last line doesn't end in whitespace (except, perhaps, newlines), and
* the second line (after the initial whitespace) begins with more whitespace than some later line

Here are a couple example strings:
* "\n a\nb"
* "\n a\n  b\nc"
* "\n  a\n b"

YAML::load throws an ArgumentError with a syntax error on the line that begins with less leading
whitespace.  
* YAML.load YAML.dump("\n a\nb") #=> ArgumentError: syntax error on line 3, col 0: `b'
* YAML.load YAML.dump("\n a\n  b\nc") #=> ArgumentError: syntax error on line 4, col 0: `c'
* YAML.load YAML.dump("\n  a\n b") #=> ArgumentError: syntax error on line 3, col 1: ` b'

This has been observed in ruby-1.8.6p0 and ruby-1.8.7p0.

Here is another observation of this same bug: http://blog.smartlogicsolutions.com/2008/09/04/ruby-patch-to-fix-broken-yamldump-for-multi-line-strings-stringto_yaml/


----------------------------------------
http://redmine.ruby-lang.org