fix removing field with reference to array items & specs

Fixes #1990
This commit is contained in:
Colin Surprenant 2014-10-30 15:59:06 -04:00 committed by Jordan Sissel
parent df67763f43
commit 1a095fccb9
2 changed files with 9 additions and 2 deletions

View file

@ -46,7 +46,7 @@ module LogStash::Util
def del(accessor)
target, key = lookup(accessor)
target.delete(key)
target.is_a?(Array) ? target.delete_at(key.to_i) : target.delete(key)
end
private

View file

@ -161,7 +161,14 @@ describe LogStash::Util::Accessors, :if => true do
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
it "should handle delete of array element" do
str = "[geocoords][0]"
data = { "geocoords" => [4, 2] }
accessors = LogStash::Util::Accessors.new(data)
insist { accessors.del(str) } == 4
insist { data } == { "geocoords" => [2] }
end end
context "using invalid encoding" do
it "strinct_set should raise on non UTF-8 string encoding" do