Skip to content

Commit

Permalink
LIR: merge arrays of divergent types
Browse files Browse the repository at this point in the history
Specifically this change explictly checks for the Array type to merge into and pushes into the array instead of relying only on the + concat.

Fixes #8827

Fixes #8831
  • Loading branch information
jakelandis committed Dec 11, 2017
1 parent cdb4f0c commit 7fddc4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions logstash-core/lib/logstash/compiler/lscl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def expr_attributes
# interpreted as `{"match" => {"baz" => "bar", "foo" => "blub"}}`.
# (NOTE: this bypasses `AST::Hash`'s ability to detect duplicate keys)
hash[k] = existing.merge(v)
elsif existing.kind_of?(::Array)
hash[k] = existing.push(*v)
else
hash[k] = existing + v
end
Expand Down
26 changes: 26 additions & 0 deletions logstash-core/spec/logstash/compiler/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,32 @@ def j
end
end

describe "a plugin with multiple array parameter types" do
let(:plugin_source) { "generator { aarg => [1] aarg => [2] aarg => [3]}" }
let(:expected_plugin_args) do
{
"aarg" => [1, 2, 3]
}
end

it "should contain the plugin" do
expect(c_plugin).to ir_eql(j.iPlugin(INPUT, "generator", expected_plugin_args))
end
end

describe "a plugin with multiple parameter types that converge to an array" do
let(:plugin_source) { "generator { aarg => [1] aarg => 2 aarg => '3' aarg => [4] }"}
let(:expected_plugin_args) do
{
"aarg" => [1, 2, "3", 4]
}
end

it "should contain the plugin" do
expect(c_plugin).to ir_eql(j.iPlugin(INPUT, "generator", expected_plugin_args))
end
end

describe "a filter plugin that repeats a Hash directive" do
let(:source) { "input { } filter { #{plugin_source} } output { } " }
subject(:c_plugin) { compiled[:filter] }
Expand Down

0 comments on commit 7fddc4a

Please sign in to comment.