Tomlyn
Tomlyn copied to clipboard
new line inserted incorrectly when saved in file
Considering a simple toml like this:
[package]
authors = [ "me", "I", "myself" ]
name = "proj"
version = "0.0.1"
[profile]
Loading and saving it with this code cause new line to be inserted at the wrong place
TomlTable model;
using (var file = File.OpenRead("file.toml"))
{
using StreamReader reader = new(file);
model = Toml.ToModel(reader.ReadToEnd());
}
using (var file = File.OpenWrite("save.toml"))
{
using StreamWriter sw = new(file);
var str = Toml.FromModel(model);
sw.Write(str);
}
Content of "save.toml" is the following:
[package]
name = "proj"
version = "0.0.1"
authors = ["me", "I", "myself"]
[profile]
note the new line after version and not after authors
ModelToTomlTransform sorts primitives above non-primitives, but preserves leading trivia (the newline before authors). I'm unfamiliar with the rationale behind primitive sorting, but I don't know if this is actually a bug.
Fixed via ee3e3ca5b1f016b0db21ceb74d6c85d28a08ca16