Skip to content

Commit

Permalink
Merge pull request #8 from erizocosmico/fix/lookup-map-slice
Browse files Browse the repository at this point in the history
fix panic in lookup for multiple maps
  • Loading branch information
mcuadros committed Jun 27, 2023
2 parents cd0454b + 686eb6d commit 5415b5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func mergeValue(values []reflect.Value) reflect.Value {

sample := values[0]
mergeable := isMergeable(sample)

t := sample.Type()
if mergeable {
t = t.Elem()
Expand Down Expand Up @@ -236,12 +235,11 @@ func isAggregable(v reflect.Value) bool {
}

func isMergeable(v reflect.Value) bool {
k := v.Kind()
return k == reflect.Map || k == reflect.Slice
return v.Kind() == reflect.Slice
}

func hasIndex(s string) bool {
return strings.Index(s, IndexOpenChar) != -1
return strings.Contains(s, IndexOpenChar)
}

func parseIndex(s string) (string, int, error) {
Expand Down
9 changes: 9 additions & 0 deletions lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ func (s *S) TestAggregableLookupString_Complex(c *C) {
value, err = LookupString(mapComplexFixture, "list.baz")
c.Assert(err, IsNil)
c.Assert(value.Interface(), DeepEquals, []int{1, 2, 3})

value, err = LookupString(mapComplexFixture, "list")
c.Assert(err, IsNil)
c.Assert(value.Interface(), DeepEquals, []map[string]interface{}{
{"baz": 1},
{"baz": 2},
{"baz": 3},
})

}

func (s *S) TestAggregableLookup_EmptySlice(c *C) {
Expand Down

0 comments on commit 5415b5b

Please sign in to comment.