Commit 35f78d5
Fix invalid TOML from commented multi-line values (#1081)
* Fix invalid TOML from commented multi-line values
A struct field marked `commented` that renders across multiple lines — a
multiline string or a multiline array (via the `multiline` tag or
SetArraysMultiline) — only had its first line prefixed with the `#`
comment marker. The continuation lines were emitted as live TOML and
failed to parse, e.g.:
# s = """
line1
line2"""
encodeKeyValue now prefixes every physical line of a commented value,
guarded by `if commented` so the common path is unchanged (allocs/op and
B/op are byte-identical in the Marshal benchmarks).
This was surfaced by a generative validity oracle (random struct types,
tags, options and values) that re-parses every marshaled output: the
multiline-string variant produced invalid TOML in every release back to
v2.3.x; the multiline-array variant regressed in v2.4 as more multiline
forms began to be honored.
Also restores the v2.3 layout for `commented` combined with
SetIndentTables (the comment marker stays at column zero, with the table
indentation inside the comment), and adds audit_flags_test.go: an
exhaustive regression suite for the encoder option x struct-tag matrix
and the decoder behaviors reworked by the v2.4.0 reimplementation,
including guards for the #1075 and #1079 fixes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Use promoted field access in embedded-tag test (staticcheck QF1008)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 25fc130 commit 35f78d5
2 files changed
Lines changed: 614 additions & 2 deletions
0 commit comments