diff options
author | Sergey Grebenshchikov <sgreben@gmail.com> | 2018-06-17 16:01:57 +0200 |
---|---|---|
committer | Sergey Grebenshchikov <sgreben@gmail.com> | 2018-06-17 16:01:57 +0200 |
commit | 24e934443db4773b7ec06b7bf1d30ff2ae22685b (patch) | |
tree | 0452008e1e0ef23730c289d83b351bc63bc02736 /cmd | |
parent | 6d38b596f52f526f245a07de803109e5a6e0117c (diff) |
Skip invalid values in flatten()
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/jp/split.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/cmd/jp/split.go b/cmd/jp/split.go index acca93c..2220c37 100644 --- a/cmd/jp/split.go +++ b/cmd/jp/split.go @@ -1,8 +1,6 @@ package main -import ( - "reflect" -) +import "reflect" var indexableKind = map[reflect.Kind]bool{ reflect.Slice: true, @@ -12,15 +10,18 @@ var indexableKind = map[reflect.Kind]bool{ func flatten(in [][]reflect.Value) (out []reflect.Value) { for _, a := range in { for _, v := range a { + if !v.IsValid() { + continue + } if indexableKind[v.Kind()] { sub := make([]reflect.Value, v.Len()) for j := 0; j < v.Len(); j++ { - sub = append(sub, v.Index((j))) + sub = append(sub, v.Index(j)) } out = append(out, flatten([][]reflect.Value{sub})...) continue } - if v.IsValid() && v.CanInterface() { + if v.CanInterface() { if sub, ok := v.Interface().([]interface{}); ok { for i := range sub { out = append(out, reflect.ValueOf(sub[i])) |