xoofx/Tomlyn

Nested TomlTable may generate incorrect result

lexchou-aspose opened this issue · 1 comments

Code to reproduce:

            var root = new Tomlyn.Model.TomlTable()
            {
                {
                    "root",
                    new Tomlyn.Model.TomlTable()
                    {
                        {"a", "a" },
                        {"b",
                            new Tomlyn.Model.TomlTable()
                            {
                                { "d", "d"}
                            }
                        },
                        {"c", "c" },

                    }
                }
            };
            var toml = Tomlyn.Toml.FromModel(root);
            var root2 = Tomlyn.Toml.ToModel(toml);

This will generates:

[level1]
a = "a"
[level1.b]
d = "d"
[level1]
c = "c"

And reload it will fail with exception: Tomlyn.TomlException: '(5,1) : error : The key level1 is already defined at (1,1) with [level1]␍␤a = "a" and cannot be redefined

The _order in TomlTable will record the order of TomlTable's elements, primitive elements should be serialized prior to the table/array elements.

xoofx commented

Fixed by commit 9d6ebf3