logstash-filter-kv 4.1.1 → 4.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c2b2e468b13494eda3ab5a4252ec1bc3b1ac73516c7de0f767d5f3a21d1c467
4
- data.tar.gz: 145252f085544e2edbceef88a6bef4cc720f6ce745e022150c25657588c3f6d8
3
+ metadata.gz: e108f33865f7afc5f0b397d3ba6ae37b93cf664c6e8f6a8d9bf74650c987954c
4
+ data.tar.gz: aded17fb29c331fe4d68ae280d2ed884e968ae180e6539a313c66b8399952be4
5
5
  SHA512:
6
- metadata.gz: 718f14bae4895dd2d9cfc252abaace7ae1f784703ec569fb9143946d21378d638889dca25db6f430bdaa25f7838eedda6c2e08eab76d520385701b7171752bcb
7
- data.tar.gz: acee9e93136b19746cac5714cf46d5d45e0780caba1ab935aa42a1f26baaa45a111b5214b04cb7dff6499e11a2f6011053d7a46180f8c9b6d78419d80f5b2e13
6
+ metadata.gz: e122414de884300d596a3d7da38f6408e1a1a42d32894013dd8c8fea533bcf18ac90619cc0ca544c68c552ab0a8e1c8891d1d15d2ee60aeb4c028b7f396443be
7
+ data.tar.gz: d667872a513d33403b7b26e69a876787ae985c515dac645948f3536f67d7b04175ec727a7f76b97d804b3934f0ee8699cd7d849a1b93f692b3c067647331ed39
@@ -1,3 +1,7 @@
1
+ ## 4.1.2
2
+ - bugfix: improves trim_key and trim_value to trim any _sequence_ of matching characters from the beginning and ends of the corresponding keys and values; a previous implementation limitited trim to a single character from each end, which was surprising.
3
+ - bugfix: fixes issue where we can fail to correctly break up a sequence that includes a partially-quoted value followed by another fully-quoted value by slightly reducing greediness of quoted-value captures.
4
+
1
5
  ## 4.1.1
2
6
  - bugfix: correctly handle empty values between value separator and field separator (#58)
3
7
 
@@ -56,6 +56,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
56
56
  | <<plugins-{type}s-{plugin}-default_keys>> |<<hash,hash>>|No
57
57
  | <<plugins-{type}s-{plugin}-exclude_keys>> |<<array,array>>|No
58
58
  | <<plugins-{type}s-{plugin}-field_split>> |<<string,string>>|No
59
+ | <<plugins-{type}s-{plugin}-field_split_pattern>> |<<string,string>>|No
59
60
  | <<plugins-{type}s-{plugin}-include_brackets>> |<<boolean,boolean>>|No
60
61
  | <<plugins-{type}s-{plugin}-include_keys>> |<<array,array>>|No
61
62
  | <<plugins-{type}s-{plugin}-prefix>> |<<string,string>>|No
@@ -69,6 +70,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
69
70
  | <<plugins-{type}s-{plugin}-trim_key>> |<<string,string>>|No
70
71
  | <<plugins-{type}s-{plugin}-trim_value>> |<<string,string>>|No
71
72
  | <<plugins-{type}s-{plugin}-value_split>> |<<string,string>>|No
73
+ | <<plugins-{type}s-{plugin}-value_split_pattern>> |<<string,string>>|No
72
74
  |=======================================================================
73
75
 
74
76
  Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
@@ -444,4 +446,4 @@ See `field_split_pattern` for examples.
444
446
 
445
447
 
446
448
  [id="plugins-{type}s-{plugin}-common-options"]
447
- include::{include_path}/{type}.asciidoc[]
449
+ include::{include_path}/{type}.asciidoc[]
@@ -331,8 +331,8 @@ class LogStash::Filters::KV < LogStash::Filters::Base
331
331
  )
332
332
  end
333
333
 
334
- @trim_value_re = Regexp.new("^[#{@trim_value}]|[#{@trim_value}]$") if @trim_value
335
- @trim_key_re = Regexp.new("^[#{@trim_key}]|[#{@trim_key}]$") if @trim_key
334
+ @trim_value_re = Regexp.new("^[#{@trim_value}]+|[#{@trim_value}]+$") if @trim_value
335
+ @trim_key_re = Regexp.new("^[#{@trim_key}]+|[#{@trim_key}]+$") if @trim_key
336
336
 
337
337
  @remove_char_value_re = Regexp.new("[#{@remove_char_value}]") if @remove_char_value
338
338
  @remove_char_key_re = Regexp.new("[#{@remove_char_key}]") if @remove_char_key
@@ -422,8 +422,8 @@ class LogStash::Filters::KV < LogStash::Filters::Base
422
422
  open_pattern = /#{Regexp.quote(quote_sequence)}/
423
423
  close_pattern = /#{Regexp.quote(close_quote_sequence)}/
424
424
 
425
- # matches a sequence of zero or more characters that is followed by the `close_quote_sequence`
426
- quoted_value_pattern = /(?:.)*?(?=#{Regexp.quote(close_quote_sequence)})/
425
+ # matches a sequence of zero or more characters are _not_ the `close_quote_sequence`
426
+ quoted_value_pattern = /[^#{Regexp.quote(close_quote_sequence)}]*/
427
427
 
428
428
  /#{open_pattern}(#{quoted_value_pattern})#{close_pattern}/
429
429
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-kv'
4
- s.version = '4.1.1'
4
+ s.version = '4.1.2'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Parses key-value pairs"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -730,6 +730,59 @@ describe LogStash::Filters::KV do
730
730
  end
731
731
  end
732
732
 
733
+ describe "trim_key/trim_value options : trim multiple matching characters from either end" do
734
+ subject do
735
+ plugin = LogStash::Filters::KV.new(options)
736
+ plugin.register
737
+ plugin
738
+ end
739
+
740
+ let(:data) { {"message" => message} }
741
+ let(:event) { LogStash::Event.new(data) }
742
+
743
+
744
+ context 'repeated same-character sequence' do
745
+ let(:message) { "key1= value1 with spaces | key2 with spaces =value2" }
746
+ let(:options) {
747
+ {
748
+ "field_split" => "|",
749
+ "value_split" => "=",
750
+ "trim_value" => " ",
751
+ "trim_key" => " "
752
+ }
753
+ }
754
+
755
+ it 'trims all the right bits' do
756
+ subject.filter(event)
757
+ expect(event.get('key1')).to eq('value1 with spaces')
758
+ expect(event.get('key2 with spaces')).to eq('value2')
759
+ end
760
+ end
761
+
762
+ context 'multi-character sequence' do
763
+ let(:message) { "to=<foo@example.com>, orig_to=<bar@example.com>, %+relay=mail.example.com[private/dovecot-lmtp], delay=2.2, delays=1.9/0.01/0.01/0.21, dsn=2.0.0, status=sent (250 2.0.0 <foo@example.com> YERDHejiRSXFDSdfUXTV Saved) " }
764
+ let(:options) {
765
+ {
766
+ "field_split" => " ",
767
+ "value_split" => "=",
768
+ "trim_value" => "<>,",
769
+ "trim_key" => "%+"
770
+ }
771
+ }
772
+
773
+ it 'trims all the right bits' do
774
+ subject.filter(event)
775
+ expect(event.get('to')).to eq('foo@example.com')
776
+ expect(event.get('orig_to')).to eq('bar@example.com')
777
+ expect(event.get('relay')).to eq('mail.example.com[private/dovecot-lmtp]')
778
+ expect(event.get('delay')).to eq('2.2')
779
+ expect(event.get('delays')).to eq('1.9/0.01/0.01/0.21')
780
+ expect(event.get('dsn')).to eq('2.0.0')
781
+ expect(event.get('status')).to eq('sent')
782
+ end
783
+ end
784
+ end
785
+
733
786
  describe "remove_char_key/remove_char_value options : remove all characters in keys/values whatever their position" do
734
787
  subject do
735
788
  plugin = LogStash::Filters::KV.new(options)
@@ -833,6 +886,40 @@ describe "multi character splitting" do
833
886
  it_behaves_like "parsing all fields and values"
834
887
  end
835
888
 
889
+ context 'multi-char field split pattern with value that begins quoted and contains more unquoted' do
890
+ let(:message) { 'foo=bar!!!!!baz="quoted stuff" and more unquoted!!!!!msg="fully-quoted with a part! of the separator"!!!!!blip="this!!!!!is it"!!!!!empty=""!!!!!non-empty="foo"' }
891
+ let(:options) {
892
+ {
893
+ "field_split_pattern" => "!!!!!"
894
+ }
895
+ }
896
+ it 'gets the right bits' do
897
+ subject.filter(event)
898
+ expect(event.get("foo")).to eq('bar')
899
+ expect(event.get("baz")).to eq('"quoted stuff" and more unquoted')
900
+ expect(event.get("msg")).to eq('fully-quoted with a part! of the separator')
901
+ expect(event.get("blip")).to eq('this!!!!!is it')
902
+ expect(event.get("empty")).to be_nil
903
+ expect(event.get("non-empty")).to eq('foo')
904
+ end
905
+ end
906
+
907
+ context 'standard field split pattern with value that begins quoted and contains more unquoted' do
908
+ let(:message) { 'foo=bar baz="quoted stuff" and more unquoted msg="some fully-quoted message " empty="" non-empty="foo"' }
909
+ let(:options) {
910
+ {
911
+ }
912
+ }
913
+ it 'gets the right bits' do
914
+ subject.filter(event)
915
+ expect(event.get("foo")).to eq('bar')
916
+ expect(event.get("baz")).to eq('quoted stuff') # NOTE: outside the quotes is truncated because field split pattern wins.
917
+ expect(event.get("msg")).to eq('some fully-quoted message ')
918
+ expect(event.get("empty")).to be_nil
919
+ expect(event.get("non-empty")).to eq('foo')
920
+ end
921
+ end
922
+
836
923
  context "field and value split multi" do
837
924
  let(:message) { "hello::world__foo::bar__baz::fizz__doublequoted::\"hello world\"__singlequoted::'hello world'__bracketsone::(hello world)__bracketstwo::[hello world]__bracketsthree::<hello world>" }
838
925
  let(:options) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-kv
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-23 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement