Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new line inserted incorrectly when saved in file #65

Open
HUD-Software opened this issue Jun 12, 2023 · 1 comment
Open

new line inserted incorrectly when saved in file #65

HUD-Software opened this issue Jun 12, 2023 · 1 comment
Labels
bug Something isn't working PR welcome User contribution/PR is welcome

Comments

@HUD-Software
Copy link

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

@xoofx xoofx added bug Something isn't working PR welcome User contribution/PR is welcome labels Aug 4, 2023
@lilith
Copy link
Contributor

lilith commented Jan 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome User contribution/PR is welcome
Projects
None yet
Development

No branches or pull requests

3 participants