Skip to content

Commit

Permalink
fix: empty TOML table (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
elibroftw authored Feb 7, 2024
1 parent 6e21c9f commit d4e16a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/yqlib/decoder_toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
fullPath := dec.getFullPath(currentNode.Child())
log.Debug("!!!fullpath: %v", fullPath)

tableValue := dec.parser.Expression()
if tableValue.Kind != toml.KeyValue {
log.Debug("got an empty table, returning")
return true, nil
}

hasValue := dec.parser.NextExpression()
if !hasValue {
return false, fmt.Errorf("error retrieving table %v value: %w", fullPath, dec.parser.Error())
Expand All @@ -277,12 +283,6 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
Tag: "!!map",
}

tableValue := dec.parser.Expression()
if tableValue.Kind != toml.KeyValue {
log.Debug("got an empty table, returning")
return true, nil
}

runAgainstCurrentExp, err := dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue)
log.Debugf("table node err: %w", err)
if err != nil && !errors.Is(io.EOF, err) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/yqlib/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ var sampleArrayTableExpected = `owner:
suburb: nice
`

var emptyTable = `
[dependencies]
`

var emptyTableExpected = `dependencies: []`

var sampleWithHeader = `
[servers]
Expand Down Expand Up @@ -199,6 +205,12 @@ var tomlScenarios = []formatScenario{
expected: sampleArrayTableExpected,
scenarioType: "decode",
},
{
description: "Parse: Empty Table",
input: emptyTable,
expected: emptyTableExpected,
scenarioType: "decode",
},
{
description: "Parse: with header",
skipDoc: true,
Expand Down

0 comments on commit d4e16a4

Please sign in to comment.