Repository navigation
Keep dotted keys separate from table headers - #103
Closed
jonathangreen wants to merge 1 commit into
Closed
jonathangreen wants to merge 1 commit into
jonathangreen wants to merge 1 commit into
Conversation
tomlkit models a dotted key such as b.c = 1 as a table, so sorted_children_table grouped it with the [header] tables. That caused two corruptions. A dotted key was rendered after any header that sorted before it, and the header captured it: top.key = 1 followed by [tbl] came out as tbl.top.key. And a dotted key and a header with the same name were coalesced into one table, which tomlkit renders without its parent prefix: [a] containing b.c = 1 followed by [a.b.e] came out as a top-level [b.e]. Dotted keys are key/value lines. Group and sort them with the keys, so they always render ahead of the headers and are never merged with one. Found by running the toml-lang/toml-test suite.
Contributor
|
#102 also fixes this. The only behaviour difference shown by your testcases is that in |
Owner
|
resolved separately by 0.25.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tomlkit models a dotted key such as
b.c = 1as a table, and the sorter grouped it with the[header]tables of the same parent. That corrupted two kinds of document:A dotted key was rendered after a header and captured by it. Any header that sorted before the dotted key moved ahead of it in the output, so the key line landed inside that header's scope.
came out as
A dotted key and a header with the same name were coalesced into one table. tomlkit renders a dotted-key table without its parent prefix, so the merged header lost its prefix.
came out as
Fix
Dotted keys are key/value lines, so
sorted_children_tablenow groups and sorts them with the keys instead of the headers. They always render ahead of the headers of their table, and a dotted key is never merged with a header of the same name. Sibling dotted keys (a.b = 1anda.c = 2), which tomlkit stores as separate entries, are still coalesced so their children sort together.Behaviour change
With key sorting enabled, dotted keys now interleave alphabetically with the plain keys of their table. Previously they were always placed after the plain keys. For example:
used to sort to
and now sorts to
Tests
Two new example files under
tests/examples, wired into the existing fixture test:dotted-key-header.toml: a dotted key beside a header of the same name at the top level, inside a table, and as an array of tables. Output must equal input.dotted-key-order.toml: dotted keys at the top level, in a table, and in array-of-tables elements, each followed by headers. Checked with key sorting on and off.