Hi! For yaml and newlines, this has been posted before (e.g. issue 1758 on redm= ine). I don't think the JSON bug has been reported, so I recommend opening an issue for that. Thanks! Marc-Andr=E9 On Mon, Sep 28, 2009 at 8:40 PM, Caleb Clausen <caleb / inforadical.net> wrot= e: > 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_pro= c > json/common.rb:122:in `parse': 574: unexpected token at '"foobar"' > (JSON::ParserError) > =A0 =A0 =A0 =A0from json/common.rb:122:in `parse' > =A0 =A0 =A0 =A0from -e:1:in `<main>' > > $ 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_pro= c > json/common.rb:122:in `parse': 618: unexpected token at '"foobar"' > (JSON::ParserError) > =A0 =A0 =A0 =A0from json/common.rb:122:in `parse' > =A0 =A0 =A0 =A0from -e:1:in `<main>' > > > 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_pro= c > ["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? > >