mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
Merge pull request #2051 from talevy/fix/1401
Fix for handling accessor sets on array elements.
This commit is contained in:
commit
df67763f43
2 changed files with 9 additions and 1 deletions
|
@ -37,7 +37,7 @@ module LogStash::Util
|
|||
|
||||
def set(accessor, value)
|
||||
target, key = lookup(accessor)
|
||||
target[key] = value
|
||||
target[target.is_a?(Array) ? key.to_i : key] = value
|
||||
end
|
||||
|
||||
def strict_set(accessor, value)
|
||||
|
|
|
@ -140,6 +140,14 @@ describe LogStash::Util::Accessors, :if => true do
|
|||
insist { data } == { "hello" => { "world" => ["foo", "bar"] } }
|
||||
end
|
||||
|
||||
it "should set element within array value" do
|
||||
str = "[hello][0]"
|
||||
data = {"hello" => ["foo", "bar"]}
|
||||
accessors = LogStash::Util::Accessors.new(data)
|
||||
insist { accessors.set(str, "world") } == "world"
|
||||
insist { data } == {"hello" => ["world", "bar"]}
|
||||
end
|
||||
|
||||
it "should retrieve array item" do
|
||||
data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } }
|
||||
accessors = LogStash::Util::Accessors.new(data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue