Skip to content

Commit

Permalink
Bug fix: decode TOML array of tables (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcheadle-vmware authored Apr 26, 2022
1 parent 4c2f681 commit b11b9ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/orderedmap/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ func (c Conversion) fromUnorderedMaps(object interface{}) interface{} {
}
return typedObj

// some sources (e.g. toml library) yield specific type of slices.
// slices in Go are not covariant, so each flavor of slice must have its own case, here.
// process these exactly the same way we do for generic slices (prior case)
case []map[string]interface{}:
resultArray := make([]interface{}, len(typedObj))
for i, item := range typedObj {
resultArray[i] = c.fromUnorderedMaps(item)
}
return resultArray
default:
return typedObj
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/yamltemplate/filetests/ytt-library/toml.tpltest
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ fragment:
- piece2
#@ end

#@ arrayOfTables = '''
#@ [[stuff]]
#@ a = 1
#@
#@ [[stuff]]
#@ b = 2
#@ '''

encode:
test1: #@ toml.encode({})
test2: #@ toml.encode({"a": [1,2,3,456], "b": "str"})
Expand All @@ -17,6 +25,7 @@ encode:
decode:
test1: #@ toml.decode("")
test2: #@ toml.decode('a = [ 1, 2, 3, 456 ]\nb = "str"')
test3: #@ toml.decode(arrayOfTables)

+++

Expand Down Expand Up @@ -55,3 +64,7 @@ decode:
- 3
- 456
b: str
test3:
stuff:
- a: 1
- b: 2

0 comments on commit b11b9ea

Please sign in to comment.