Support go-toml v2.4.3 - #553
Merged
Merged
Conversation
go-toml v2.4 rejects encoding a bare value as a document root, which the TOML writer relied on when the top level value isn't a table - the result of selecting a scalar or list out of a document. Every *_to_toml case in the cross format tests failed with "cannot encode a X as a document root", as reported in the Debian build. The writer now encodes those values against a placeholder key and strips the "<key> = " prefix back off, so go-toml still owns value formatting and the output is unchanged. Using the inline tag option on the placeholder also fixes a top level list of tables, which previously emitted table headers with an empty key. Fixes #550
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 #550
Problem
Debian's build of dasel against go-toml v2.4.2 fails every
*_to_tomlcross-format test withtoml: cannot encode a X as a document root.go-toml v2.4 added a check in
encodeRootthat a document root must be a table. Earlier versions encoded whatever they were given. The TOML writer depended on that leniency: when the top level value isn't a map — the result of selecting a scalar or list out of a document — it handed the value straight toencoder.Encode. Sodasel -i json -o toml 'hello'printing'world'only worked because go-toml permitted a bare value at the root.We were also pinned to a pseudo-version (
v2.2.5-0.20250826075308-…), several releases behind and missing the fixes from GHSA-frc4-6h9q-39fq.Fix
encodeRootValuehandles non-map roots by wrapping the value in a generated single-field struct taggedtoml:"v,inline", encoding that, and stripping thev =prefix. go-toml still owns all value formatting, so quoting and array style are unchanged.Verification
Built binaries from
masterand from this branch and diffed their output across scalars, lists, nested lists, quoted and multiline strings, null, whole documents, and the complex-example round-trip, in both normal and--compactmode.Output is byte-identical except one case, which improved:
[[]]⏎a = 1⏎⏎[[]]⏎a = 2[{a = 1}, {a = 2}]The old output there was invalid TOML — table headers with an empty key, which dasel itself cannot parse back. The
inlinetag option fixes it as a side effect. It is a behaviour change, so it is called out in the changelog rather than left silent.Added
TestTomlWriter_RootValuecovering 12 root-value shapes plus the null-root error, in both compact and non-compact mode, so a future go-toml bump cannot regress this quietly.Note on v2
This targets the v3
masterbranch. Debian packages dasel v2, where the writer code differs, so if their build needs the same fix that is a separate backport — I have not assumed this patch transfers.