Skip to content

Commit c598b80

Browse files
authored
Merge pull request #6 from arduino/scerza/fix-subtree-index-extract
Fix `ExtractSubIndexLists` returning a list containing a single empty string if root property is not found
2 parents e4121da + 018a4e7 commit c598b80

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

properties.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,9 @@ func (m *Map) ExtractSubIndexLists(root string) []string {
636636

637637
// if there are no subindexed then return the whole "roox.xxx" subtree
638638
if !haveIndexedProperties {
639-
res = append(res, m.Get(root))
639+
if value, ok := m.GetOk(root); ok {
640+
res = append(res, value)
641+
}
640642
}
641643

642644
return res

properties_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ func TestExtractSubIndexLists(t *testing.T) {
356356
"quattro.discovery.required": "itemA",
357357
"quattro.discovery.required.1": "itemB",
358358
"quattro.discovery.required.2": "itemC",
359+
"cinque.discovery.something": "itemX",
359360
}
360361
m := NewFromHashmap(data)
361362

@@ -379,4 +380,7 @@ func TestExtractSubIndexLists(t *testing.T) {
379380
require.Len(t, s4, 2)
380381
require.Equal(t, s4[0], "itemB")
381382
require.Equal(t, s4[1], "itemC")
383+
384+
s5 := m.ExtractSubIndexLists("cinque.discovery.required")
385+
require.Len(t, s5, 0)
382386
}

0 commit comments

Comments
 (0)