setting a list config to empty array should not result in nil

if a plugin author defines a config parameter as:

  config :retryable_codes, :validate => :number, :list => true, :default => [429]

And a user configures the plugin as:

  plugin { retryable_codes => [] }

It's expected that the retryable_codes parameter is an empty array and not a nil object

This PR changes this behaviour to generate an empty array

Fixes #10179
This commit is contained in:
Joao Duarte 2018-11-26 22:11:47 +00:00 committed by João Duarte
parent d6a2299997
commit e4159d0fb6
2 changed files with 3 additions and 3 deletions

View file

@ -323,7 +323,7 @@ module LogStash::Config::Mixin
if config_settings[:list]
value = Array(value) # coerce scalars to lists
# Empty lists are converted to nils
return true, nil if value.empty?
return true, [] if value.empty?
validated_items = value.map {|v| validate_value(v, config_val)}
is_valid = validated_items.all? {|sr| sr[0] }

View file

@ -132,8 +132,8 @@ describe LogStash::Config::Mixin do
context "with an empty list" do
let(:strings) { [] }
it "should return nil" do
expect(subject.strings).to be_nil
it "should return an empty list" do
expect(subject.strings).to be_empty
end
end