Bug #1311
closedYAML::dump creates strings YAML::load cannot parse
Description
=begin
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/
=end
Files
Updated by rampion (Noah Easterly) over 15 years ago
=begin
Correction: should read "the second line (after the initial newline)"
=end
Updated by daz (Dave B) over 15 years ago
- File syck_scan_scalar.patch syck_scan_scalar.patch added
- File test_yaml.patch test_yaml.patch added
=begin
Good reports, thanks.
I've found a workaround but I'm not sure enough about the YAML spec to guarantee that it's the correct fix.
The patch is mild - it just forces one style over another in the same way as the existing code and allows the new tests to pass along with the rest.
Two patches to 1.9.2dev - these files don't change often ;)
?CHANGELOG: Wed Mar 25 20:06:10 2009 Dave B daz@d10.karoo.co.uk
* ext/syck/emitter.c: Set SCAN_WHITEEDGE flag when
scalar begins with newline [ruby-core:23006][Bug #1311]
* test/yaml/test_yaml.rb: add new tests and comment old
Test::Unit::TestSuite code to enable them to run as $0
=end
Updated by coatl (caleb clausen) about 15 years ago
- File test_yaml2.patch test_yaml2.patch added
- File syck_scan_scalar2.patch syck_scan_scalar2.patch added
=begin
I have also been bitten by this same bug. In addition to the cases described above, this problem also occurs when the input contains just a single newline (in either unix or dos style). The patch supplied by Dave B fixes the case of a string containing just a single unix newline, but fails to fix a string with just a single dos newline (and probably the other cases initially reported, if the unix newlines are converted to dos newlines). I'm attaching slightly a slightly modified patches, which addresses the dos newline issue, and tests single dos and unix newlines.
This problem also occurs in ruby 1.9.
=end
Updated by daz (Dave B) about 15 years ago
=begin
Caleb's revisions are the way to go.
( test_yaml2.patch & syck_scan_scalar2.patch )
Harmlessly beneficial - no compatibility issues - emits YAML to the spec.
daz
=end
Updated by weppos (Simone Carletti) over 14 years ago
- File yaml-error.txt yaml-error.txt added
=begin
Here's an other test case for a similar issue.
require 'yaml'
c = File.read("yaml-error.txt")
YAML.load(YAML.dump(c))
'rgumentError: syntax error on line 34, col 0:-- from /Users/weppos/.rvm/ruby-1.8.7-p248/lib/ruby/1.8/yaml.rb:133:in
load'
from /Users/weppos/.rvm/ruby-1.8.7-p248/lib/ruby/1.8/yaml.rb:133:in `load'
from (irb):3
=end
Updated by mame (Yusuke Endoh) over 14 years ago
- Status changed from Open to Closed
=begin
Hi,
Syck is deprecated, in effect. This issue won't be fixed.
Instead, try Psych. [ruby-core:29337]
--
Yusuke Endoh mame@tsg.ne.jp
=end
Updated by coatl (caleb clausen) over 14 years ago
=begin
Yusuke Endoh and I have verified that all of the test cases reported here are fixed when using psych. For proof of most, see [ruby-core:29323]. And I just now verified the last test case is now ok, submitted by Simone Carletti. (No console dump, sorry.)
=end
Updated by nobu (Nobuyoshi Nakada) over 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
This issue was solved with changeset r27591.
Noah, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end