From 95bf8430a94c7dfc4123153adcf1b567cd356863 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Thu, 2 Feb 2017 23:45:24 +0100 Subject: [PATCH] Ignore blank tags --- lib/rackstash/fields/tags.rb | 9 ++++++--- spec/rackstash/fields/tags_spec.rb | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/rackstash/fields/tags.rb b/lib/rackstash/fields/tags.rb index 8bafe84..8e0e9af 100644 --- a/lib/rackstash/fields/tags.rb +++ b/lib/rackstash/fields/tags.rb @@ -17,7 +17,7 @@ module Rackstash def <<(tag) tag = resolve_value(tag) tag = utf8_encode(tag).freeze - @raw << tag + @raw << tag unless tag.empty? self end @@ -41,7 +41,10 @@ module Rackstash end def merge!(tags, scope: nil) - @raw.merge normalize_tags(tags, scope: scope) + tags = normalize_tags(tags, scope: scope) + tags.reject!(&:empty?) + + @raw.merge tags self end @@ -69,7 +72,7 @@ module Rackstash value.flatten! value else - utf8_encode(value).freeze + utf8_encode(value).strip.freeze end end end diff --git a/spec/rackstash/fields/tags_spec.rb b/spec/rackstash/fields/tags_spec.rb index 67c7900..c98c205 100644 --- a/spec/rackstash/fields/tags_spec.rb +++ b/spec/rackstash/fields/tags_spec.rb @@ -87,7 +87,7 @@ describe Rackstash::Fields::Tags do expect(tags.to_a).to eql ['foo', 'bar'] tags.merge! [123, 'foo', nil] - expect(tags.to_a).to eql ['foo', 'bar', '123', ''] + expect(tags.to_a).to eql ['foo', 'bar', '123'] expect(tags.to_a).to all be_frozen end @@ -123,7 +123,7 @@ describe Rackstash::Fields::Tags do end describe '#tagged?' do - it 'checks is the argument is tagged' do + it 'checks if the argument is tagged' do tags.merge! ['foo', '123'] expect(tags.tagged?('foo')).to be true @@ -144,7 +144,7 @@ describe Rackstash::Fields::Tags do expect(tags.to_set.include?('foo')).to be true expect(tags.to_set.include?(nil)).to be false - expect(tags.to_set.include?('')).to be true + expect(tags.to_set.include?('')).to be false end end