Fix doubled comma when inserting into a comma-first array#499
Merged
frostming merged 1 commit intoJun 10, 2026
Merged
Conversation
In a comma-first formatted array the separator of an item after a comment lives in that item's indent whitespace. Array.insert() copied such an indent onto the new item while also adding a trailing comma to the previous item (and, for middle inserts, to the new item), producing a double separator that no longer parses, e.g. `2,` followed by `,99`. Skip the extra commas when the copied indent already carries one.
2aab1e4 to
3313f24
Compare
Contributor
|
Thanks |
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 #494.
In a comma-first formatted array the comma that separates an item from the previous one lives in that item's indent whitespace (the parser folds
\n ,into the next group's indent when a comment ends the previous group).Array.insert()copies such an indent onto the new item, but then also adds a trailing comma to the previous item — and for middle inserts gives the new item a trailing comma too — so the output contains double separators and no longer parses:The fix skips both extra commas when the indent copied onto the new item already carries one: the embedded comma is the separator. Output is style-preserving (
,2→,99) and round-trips. Same structure as the__delitem__comma_in_indenthandling from #486, whichinsert()never got.Regression tests cover append, middle insert (both previously produced unparseable output), and front insert (comma-less indent, unchanged behavior).