Tomlyn icon indicating copy to clipboard operation
Tomlyn copied to clipboard

new line inserted incorrectly when saved in file

Open HUD-Software opened this issue 2 years ago • 1 comments

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

HUD-Software avatar Jun 12 '23 08:06 HUD-Software

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.

lilith avatar Jan 30 '24 00:01 lilith

Fixed via ee3e3ca5b1f016b0db21ceb74d6c85d28a08ca16

xoofx avatar Mar 11 '25 10:03 xoofx