mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
Fix problem accessing array-indexed fields.
This change fixes accessing fields of the form [list][0][key], where [list] is an array, [0] is the numeric index into the array, and [key] is the hash key into one of the items in the array.
This commit is contained in:
parent
e1bd6a1365
commit
82650a21ba
2 changed files with 8 additions and 1 deletions
|
@ -57,7 +57,7 @@ module LogStash::Util
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -146,6 +146,13 @@ describe LogStash::Util::Accessors, :if => true do
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue