Fix duplicated prefix and captured sibling when replacing a dotted key with a table#526
Open
Labib-Bin-Salam wants to merge 1 commit into
Open
Conversation
…y with a table
Replacing a dotted key's value with a table (e.g. ``doc["a"] = {...}`` where
``a`` was parsed from ``a.b = ...``) kept the dotted key, which both duplicated
the prefix onto the new ``[a]`` header (python-poetry#524) and let the header swallow any
sibling that follows it on round-trip (python-poetry#513).
A dotted key only renders correctly alongside a super table; when the
replacement is a non-super table it now drops the dotted key, and when an
inline sibling still follows it moves past it -- mirroring the existing
value-to-table handling. That scan now skips dotted-key tables when looking
for the first real header, which additionally fixes the same capture for a
plain value replaced by a table before a dotted key.
Fixes python-poetry#513
Fixes python-poetry#524
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.
Summary
Replacing a dotted key's value with a table corrupted the output in two ways, reported in #524 and #513.
#524 — duplicated prefix on a spurious header:
master:
#513 — a following sibling is silently swallowed (the data changes):
master:
c.dis now a child of[a].Cause
A dotted key (
a.b = 1stores keyawithis_dotted() == True) is only consistent with a super table, which renders inline. When the value is replaced by a plaindict,Container._replace_atinherits the old dotted key, but the new table is not a super table, so it renders with its own[header]while the dotted key still prefixes the children — and the header then captures every following entry that renders inline.Fix
In
_replace_at, when a non-super table replaces a dotted key:[header]), which additionally fixes the same capture for a plain value replaced by a table that sits before a dotted key.Result:
Tests
Added four regression tests in
tests/test_toml_document.py(both issue repros, a non-empty variant, and the value→table-before-dotted case). The full suite passes (1027, including the toml-test conformance suite);ruffandruff formatare clean.Fixes #513
Fixes #524