Initialize the metadata_accessors when setting the @metadata with a hash

Fixes #3198
This commit is contained in:
Pier-Hugues Pellerin 2015-05-07 22:12:12 -04:00 committed by Jordan Sissel
parent 1f7d3f550e
commit fe99f45499
2 changed files with 6 additions and 0 deletions

View file

@ -141,6 +141,7 @@ class LogStash::Event
@metadata_accessors.set(fieldref[METADATA_BRACKETS.length .. -1], value)
elsif fieldref == METADATA
@metadata = value
@metadata_accessors = LogStash::Util::Accessors.new(@metadata)
else
@accessors.set(fieldref, value)
end

View file

@ -38,6 +38,11 @@ describe LogStash::Event do
expect(subject["[foo][bar]"] = "zab").to eq("zab")
expect(subject["[foo][bar]"]).to eq("zab")
end
it "allow to set the @metadata key to a hash" do
subject["@metadata"] = { "action" => "index" }
expect(subject["[@metadata][action]"]).to eq("index")
end
end
context "#sprintf" do