From: Caleb Clausen Date: 2009-09-29T09:40:24+09:00 Subject: [ruby-core:25829] string objects don't survive round-trip in yaml&json It appears that strings containing just newlines don't emerge the same after a round-trip thru yaml. This appears to be the case in all versions of ruby's yaml library. I think it's been around forever; I vaguely remember running across this when I first started fooling with yaml. Confirmed for sure in 1.9.2dev, 1.9.1, and 1.8.6. I expect the output of all 3 of the following commands to be "\n", not an empty string: $ ruby-snapshot -v -ryaml -e 'p YAML.load YAML.dump "\n"' ruby 1.9.2dev (2009-09-28 trunk 25126) [i686-linux] "" $ ruby191 -v -ryaml -e 'p YAML.load YAML.dump "\n"' ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux] "" $ ruby186 -v -ryaml -e 'p YAML.load YAML.dump "\n"' ruby 1.8.6 (2009-06-08 patchlevel 369) [i686-linux] -e:1: warning: parenthesize argument(s) for future version -e:1: warning: parenthesize argument(s) for future version "" Json has trouble with string round-trips too; it crashes when parsing any string if at the root of the object tree to be dumped+restored. Observed in both 1.9.2dev and 1.9.1 (and 1.8.6 with json gem installed). $ ruby191 -v -rjson -e 'p JSON.parse JSON.unparse "foobar"' ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux] json/common.rb:274: warning: method redefined; discarding old recurse_proc json/common.rb:122:in `parse': 574: unexpected token at '"foobar"' (JSON::ParserError) from json/common.rb:122:in `parse' from -e:1:in `
' $ ruby -v -rjson -e 'p JSON.parse JSON.unparse "foobar"' ruby 1.9.2dev (2009-09-28 trunk 25126) [i686-linux] json/common.rb:273: warning: method redefined; discarding old recurse_proc json/common.rb:122:in `parse': 618: unexpected token at '"foobar"' (JSON::ParserError) from json/common.rb:122:in `parse' from -e:1:in `
' Note that simply enclosing the string in an array makes the problem disappear: $ ruby191 -v -rjson -e 'p JSON.parse JSON.unparse ["foobar"]' ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux] json/common.rb:274: warning: method redefined; discarding old recurse_proc ["foobar"] (Some overlong lines in console output have been shortened in hopes of preventing ugly wrapping.) I'm pretty sure these are both bugs, but I may be missing something. Before I go ahead and report them, does anyone know a reason why they shouldn't be considered bugs?