Fix stale dotted-key prefix when replacing a table value with a plain dict#528
Closed
gaoflow wants to merge 1 commit into
Closed
Fix stale dotted-key prefix when replacing a table value with a plain dict#528gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
… dict
After parsing 'fruit.apple = true', the key 'fruit' in the document
body retained _dotted=True from _handle_dotted_key. When the entire
table was then replaced via doc['fruit'] = {'a': 1}, _replace_at
reused the old key object (same name + same kind), keeping the stale
_dotted flag. This caused rendering to both emit a [fruit] header
(because the new table is not a super-table) and prefix every child
with 'fruit.' (because key.is_dotted() was true), producing the
invalid output '[fruit]\nfruit.a = 1' instead of 'a = 1'.
Fix: clear _dotted on the reused key in _replace_at. The dotted
heritage belongs to the original parse — a full table replacement
gets fresh rendering behaviour. Incremental modifications (like
doc['fruit']['banana'] = 2) are unaffected because they don't
reach the document-level _replace_at path.
Contributor
Author
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.
Fixes #524.
After parsing
fruit.apple = true, the document-body keyfruitretained_dotted=Truefrom_handle_dotted_key. When the whole table is later replaced viadoc['fruit'] = {'a': 1},_replace_atreuses the old key object (same name + same kind), keeping the stale flag. This causes rendering to both emit a[fruit]header (new table is not a super-table) and prefix every child withfruit.(becausekey.is_dotted()is true), producing:instead of the correct
a = 1.The fix clears
_dottedon the reused key in_replace_at. The dotted heritage belongs to the original parse — a full table replacement gets fresh rendering behaviour. Incremental modifications (likedoc['fruit']['banana'] = 2) are unaffected because they only reach the table-level_replace_at, not the document-level one that reuses the dotted-marked outer key.