YamlDotNet
YamlDotNet copied to clipboard
Round tripping trailing newlines
trafficstars
Describe the bug
It looks like the IsBreak treats CRLF different from LF:
To Reproduce
crlf, fails on the chomping character, not on the newline character:
var yaml = new Serializer().Serialize(new { c = "asdf\r\n" });
yaml.Should().Be("c: > asdf\n");
lf, succeeds:
var yaml = new Serializer().Serialize(new { c = "asdf\n" });
yaml.Should().Be("c: > asdf\n");
round trip is different on 2nd serialize:
var yaml = new Serializer().Serialize(new { c = "asdf\r\n" });
yaml.Should().Be("c: >+\n asdf\n");
var s = new Deserializer().Deserialize<IDictionary<string, object>>(yaml);
s["c"].Should().Be("asdf\n");
new Serializer().Serialize(s).Should().Be(yaml);
With a CRLF you get a the + chomp hint and with only a LF you don't. This makes round trip "unstable" since when reading the yaml you always get LF (like it should) so if you export again you "lose" the chomp hint (what should not be there in the first place, I presume).