mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
fix: empty TOML table (#1936)
This commit is contained in:
parent
6e21c9f77f
commit
d4e16a413e
@ -267,6 +267,12 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
|
|||||||
fullPath := dec.getFullPath(currentNode.Child())
|
fullPath := dec.getFullPath(currentNode.Child())
|
||||||
log.Debug("!!!fullpath: %v", fullPath)
|
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()
|
hasValue := dec.parser.NextExpression()
|
||||||
if !hasValue {
|
if !hasValue {
|
||||||
return false, fmt.Errorf("error retrieving table %v value: %w", fullPath, dec.parser.Error())
|
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",
|
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)
|
runAgainstCurrentExp, err := dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue)
|
||||||
log.Debugf("table node err: %w", err)
|
log.Debugf("table node err: %w", err)
|
||||||
if err != nil && !errors.Is(io.EOF, err) {
|
if err != nil && !errors.Is(io.EOF, err) {
|
||||||
|
@ -48,6 +48,12 @@ var sampleArrayTableExpected = `owner:
|
|||||||
suburb: nice
|
suburb: nice
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var emptyTable = `
|
||||||
|
[dependencies]
|
||||||
|
`
|
||||||
|
|
||||||
|
var emptyTableExpected = `dependencies: []`
|
||||||
|
|
||||||
var sampleWithHeader = `
|
var sampleWithHeader = `
|
||||||
[servers]
|
[servers]
|
||||||
|
|
||||||
@ -199,6 +205,12 @@ var tomlScenarios = []formatScenario{
|
|||||||
expected: sampleArrayTableExpected,
|
expected: sampleArrayTableExpected,
|
||||||
scenarioType: "decode",
|
scenarioType: "decode",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Parse: Empty Table",
|
||||||
|
input: emptyTable,
|
||||||
|
expected: emptyTableExpected,
|
||||||
|
scenarioType: "decode",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Parse: with header",
|
description: "Parse: with header",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user