Skip to content

Commit

Permalink
fix removing field with reference to array items & specs
Browse files Browse the repository at this point in the history
  • Loading branch information
colinsurprenant authored and jordansissel committed Nov 18, 2014
1 parent df67763 commit 1a095fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/logstash/util/accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def strict_set(accessor, value)

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
Expand Down
9 changes: 8 additions & 1 deletion spec/util/accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@
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
Expand Down

0 comments on commit 1a095fc

Please sign in to comment.