mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Empty TOML table is an empty object
This commit is contained in:
parent
d4e16a413e
commit
5513ac8a7d
@ -267,29 +267,32 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
|
||||
fullPath := dec.getFullPath(currentNode.Child())
|
||||
log.Debug("!!!fullpath: %v", fullPath)
|
||||
|
||||
tableValue := dec.parser.Expression()
|
||||
tableNodeValue := &CandidateNode{
|
||||
Kind: MappingNode,
|
||||
Tag: "!!map",
|
||||
Content: make([]*CandidateNode, 0),
|
||||
}
|
||||
|
||||
var tableValue *toml.Node
|
||||
runAgainstCurrentExp := false
|
||||
var err error
|
||||
hasValue := dec.parser.NextExpression()
|
||||
// check to see if there is any table data
|
||||
if hasValue {
|
||||
tableValue = dec.parser.Expression()
|
||||
// next expression is not table data, so we are done
|
||||
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())
|
||||
}
|
||||
|
||||
tableNodeValue := &CandidateNode{
|
||||
Kind: MappingNode,
|
||||
Tag: "!!map",
|
||||
}
|
||||
|
||||
runAgainstCurrentExp, err := dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue)
|
||||
log.Debugf("table node err: %w", err)
|
||||
runAgainstCurrentExp, err = dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue)
|
||||
if err != nil && !errors.Is(io.EOF, err) {
|
||||
return false, err
|
||||
}
|
||||
c := Context{}
|
||||
}
|
||||
|
||||
c := Context{}
|
||||
c = c.SingleChildContext(dec.rootMap)
|
||||
err = dec.d.DeeplyAssign(c, fullPath, tableNodeValue)
|
||||
if err != nil {
|
||||
|
@ -104,3 +104,19 @@ owner:
|
||||
suburb: nice
|
||||
```
|
||||
|
||||
## Parse: Empty Table
|
||||
Given a sample.toml file of:
|
||||
```toml
|
||||
|
||||
[dependencies]
|
||||
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq -oy '.' sample.toml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
dependencies: {}
|
||||
```
|
||||
|
||||
|
@ -52,7 +52,7 @@ var emptyTable = `
|
||||
[dependencies]
|
||||
`
|
||||
|
||||
var emptyTableExpected = `dependencies: []`
|
||||
var emptyTableExpected = "dependencies: {}\n"
|
||||
|
||||
var sampleWithHeader = `
|
||||
[servers]
|
||||
|
@ -1,3 +1,9 @@
|
||||
4.40.6:
|
||||
- Fix: empty TOML table #1924 - Thanks @elibroftw
|
||||
- Fixed "all" error message #1845
|
||||
- Fixed to_entries[]
|
||||
- Bumped dependencies
|
||||
|
||||
4.40.5:
|
||||
- Fixing seg fault on bad XML #1888
|
||||
- Fixed handling of --- #1890, #1896
|
||||
|
Loading…
Reference in New Issue
Block a user