diff --git a/lib/logstash/util/accessors.rb b/lib/logstash/util/accessors.rb index 1488bd87ad8..b98615d6dab 100644 --- a/lib/logstash/util/accessors.rb +++ b/lib/logstash/util/accessors.rb @@ -57,7 +57,7 @@ def lookup(accessor) def store_path(accessor) key, path = PathCache.get(accessor) - target = path.inject(@store) {|r, k| r[k] ||= {}} + target = path.inject(@store) {|r, k| r[r.is_a?(Array) ? k.to_i : k] ||= {}} [target, key] end diff --git a/spec/util/accessors_spec.rb b/spec/util/accessors_spec.rb index 13c57dac8d0..e86e25aed37 100644 --- a/spec/util/accessors_spec.rb +++ b/spec/util/accessors_spec.rb @@ -146,6 +146,13 @@ insist { accessors.get("[hello][world][0]") } == data["hello"]["world"][0] insist { accessors.get("[hello][world][1]") } == data["hello"]["world"][1] end + + it "should retrieve array item containing hash" do + data = { "hello" => { "world" => [ { "a" => 123 }, { "b" => 345 } ], "bar" => "baz" } } + accessors = LogStash::Util::Accessors.new(data) + insist { accessors.get("[hello][world][0][a]") } == data["hello"]["world"][0]["a"] + insist { accessors.get("[hello][world][1][b]") } == data["hello"]["world"][1]["b"] + end end context "using invalid encoding" do