Can process numeric keys

Fixes: https://github.com/mikefarah/yq/issues/215
This commit is contained in:
Mike Farah 2019-04-30 09:43:09 +10:00
parent f8c1c3c1b4
commit 2dbde6b9fb
2 changed files with 11 additions and 1 deletions

View File

@ -10,7 +10,7 @@ import (
func entryInSlice(context yaml.MapSlice, key interface{}) *yaml.MapItem {
for idx := range context {
var entry = &context[idx]
if entry.Key == key {
if fmt.Sprintf("%v", entry.Key) == key {
return entry
}
}
@ -115,6 +115,7 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf
}
func readMap(context yaml.MapSlice, head string, tail []string) (interface{}, error) {
log.Debugf("readingMap %v with key %v\n", context, head)
if head == "*" {
return readMapSplat(context, tail)
}

View File

@ -18,6 +18,15 @@ b:
assertResult(t, 2, got)
}
func TestReadMap_numberKey(t *testing.T) {
var data = parseData(`
---
200: things
`)
got, _ := readMap(data, "200", []string{})
assertResult(t, "things", got)
}
func TestReadMap_splat(t *testing.T) {
var data = parseData(`
---