From 018a4e778877a3f428325f7c06ae1b539bac1ae1 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 23 Jul 2021 17:14:43 +0200 Subject: [PATCH] Fix ExtractSubIndexLists returning a list containing a single empty string if root property is not found --- properties.go | 4 +++- properties_test.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/properties.go b/properties.go index ab08ef1..4e82c60 100644 --- a/properties.go +++ b/properties.go @@ -636,7 +636,9 @@ func (m *Map) ExtractSubIndexLists(root string) []string { // if there are no subindexed then return the whole "roox.xxx" subtree if !haveIndexedProperties { - res = append(res, m.Get(root)) + if value, ok := m.GetOk(root); ok { + res = append(res, value) + } } return res diff --git a/properties_test.go b/properties_test.go index 8d83591..46f2c76 100644 --- a/properties_test.go +++ b/properties_test.go @@ -356,6 +356,7 @@ func TestExtractSubIndexLists(t *testing.T) { "quattro.discovery.required": "itemA", "quattro.discovery.required.1": "itemB", "quattro.discovery.required.2": "itemC", + "cinque.discovery.something": "itemX", } m := NewFromHashmap(data) @@ -379,4 +380,7 @@ func TestExtractSubIndexLists(t *testing.T) { require.Len(t, s4, 2) require.Equal(t, s4[0], "itemB") require.Equal(t, s4[1], "itemC") + + s5 := m.ExtractSubIndexLists("cinque.discovery.required") + require.Len(t, s5, 0) }