fix(stringify): emit root-level keys before sections - #40
Open
mahirhir wants to merge 1 commit into
Open
Conversation
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.
Problem
stringifywrites object keys in their original order, so a root-level key that comes after a nested object is written underneath that object's[section]header. When the output is read back withparse, the root key is absorbed into the section instead of staying at the top level, soparse(stringify(obj))does not returnobj:Cause
In an INI document every key after a
[section]header belongs to that section, so root-level keys can only be represented before the first section.stringifyiteratesObject.keys(data)in insertion order, which can place a root key after a section that was declared earlier in the object.Fix
Order the top-level keys so non-object (scalar) keys are written before any object/array section. Relative order within each group is preserved, and output is unchanged for objects that already list their root keys first, so the existing fixtures and tests are unaffected. Added a test for the round trip.