diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a252f..1d44840 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ -# v1.0.0 +# 1.0.2 + + - Fix: '' value behavior in `field_reference` validator [#2](https://github.com/logstash-plugins/logstash-mixin-validator_support/pull/2) + +# 1.0.1 - Introduces plugin parameter validation adapters, including initial backport for `:field_reference` validator. \ No newline at end of file diff --git a/lib/logstash/plugin_mixins/validator_support/field_reference_validation_adapter.rb b/lib/logstash/plugin_mixins/validator_support/field_reference_validation_adapter.rb index 4595e61..8b48143 100644 --- a/lib/logstash/plugin_mixins/validator_support/field_reference_validation_adapter.rb +++ b/lib/logstash/plugin_mixins/validator_support/field_reference_validation_adapter.rb @@ -16,10 +16,11 @@ module ValidatorSupport FieldReferenceValidationAdapter = NamedValidationAdapter.new(:field_reference) do |value| break ValidationResult.failure("Expected exactly one field reference, got `#{value.inspect}`") unless value.kind_of?(Array) && value.size <= 1 - break ValidationResult.success(nil) if value.empty? || value.first.nil? candidate = value.first + break ValidationResult.success(nil) if value.empty? || candidate.nil? || candidate.empty? + break ValidationResult.failure("Expected a valid field reference, got `#{candidate.inspect}`") unless field_reference_pattern =~ candidate break ValidationResult.success(candidate) diff --git a/logstash-mixin-validator_support.gemspec b/logstash-mixin-validator_support.gemspec index 20317e0..fdfaab1 100644 --- a/logstash-mixin-validator_support.gemspec +++ b/logstash-mixin-validator_support.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'logstash-mixin-validator_support' - s.version = '1.0.1' + s.version = '1.0.2' s.licenses = %w(Apache-2.0) s.summary = "Support for the plugin parameter validations introduced in recent releases of Logstash, for plugins wishing to use them on older Logstashes" s.description = "This gem is meant to be a dependency of any Logstash plugin that wishes to use validators introduced in recent versions of Logstash while maintaining backward-compatibility with earlier Logstashes. When used on older Logstash versions, it provides back-ports of the new validators." diff --git a/spec/logstash/plugin_mixins/validator_support/field_reference_validation_adapter_spec.rb b/spec/logstash/plugin_mixins/validator_support/field_reference_validation_adapter_spec.rb index 8319d96..ce07b61 100644 --- a/spec/logstash/plugin_mixins/validator_support/field_reference_validation_adapter_spec.rb +++ b/spec/logstash/plugin_mixins/validator_support/field_reference_validation_adapter_spec.rb @@ -28,6 +28,16 @@ end end + context "valid input `''`" do + # failed in version 1.0.x which was not compatible with LS 7.x behavior + it 'correctly reports the value as valid' do + is_valid_result, coerced_or_error = described_class.validate [''] + + expect(is_valid_result).to be true + expect(coerced_or_error).to be nil + end + end + [ ['link[0]'], ['][N\\//\\L][D'],