fix: empty TOML table (#1936)

This commit is contained in:
Elijah Lopez 2024-02-07 03:59:50 -05:00 committed by GitHub
parent 6e21c9f77f
commit d4e16a413e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View File

@ -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())
@ -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) {

View File

@ -48,6 +48,12 @@ var sampleArrayTableExpected = `owner:
suburb: nice
`
var emptyTable = `
[dependencies]
`
var emptyTableExpected = `dependencies: []`
var sampleWithHeader = `
[servers]
@ -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,