Fix TOML table parsing after standalone comments

Standalone TOML comments immediately inside a table/array-table no longer end the table scope, preventing subsequent keys from being flattened to the document root.
This commit is contained in:
Tomer Shalev
2026-01-31 14:41:30 +02:00
parent 2824d66a65
commit b4b96f2a68
2 changed files with 117 additions and 23 deletions
+24
View File
@@ -228,6 +228,14 @@ B = 12
name = "Tom" # name comment
`
// Repro for https://github.com/mikefarah/yq/issues/2588
// Bug: standalone comments inside a table cause subsequent key-values to be assigned at root.
var issue2588RustToolchainWithComments = `
[owner]
# comment
name = "Tomer"
`
var sampleFromWeb = `# This is a TOML document
title = "TOML Example"
@@ -550,6 +558,22 @@ var tomlScenarios = []formatScenario{
expected: rtComments,
scenarioType: "roundtrip",
},
{
skipDoc: true,
description: "Issue #2588: comments inside table must not flatten (.owner.name)",
input: issue2588RustToolchainWithComments,
expression: ".owner.name",
expected: "Tomer\n",
scenarioType: "decode",
},
{
skipDoc: true,
description: "Issue #2588: comments inside table must not flatten (.name)",
input: issue2588RustToolchainWithComments,
expression: ".name",
expected: "null\n",
scenarioType: "decode",
},
{
description: "Roundtrip: sample from web",
input: sampleFromWeb,