Merge pull request #2051 from talevy/fix/1401

Fix for handling accessor sets on array elements.
This commit is contained in:
Tal Levy 2014-11-17 14:07:39 -08:00
commit df67763f43
2 changed files with 9 additions and 1 deletions

View file

@ -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)

View file

@ -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)