Skip to content

Commit

Permalink
Merge pull request elastic#2051 from talevy/fix/1401
Browse files Browse the repository at this point in the history
Fix for handling accessor sets on array elements.
  • Loading branch information
talevy committed Nov 17, 2014
2 parents 1748f2c + dd3667e commit df67763
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/logstash/util/accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get(accessor)

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)
Expand Down
8 changes: 8 additions & 0 deletions spec/util/accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@
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)
Expand Down

0 comments on commit df67763

Please sign in to comment.