logstash-filter-kv 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60449ebe2807038eecb8421ac199171dbdb021c5ed8207d5fa37ffa5904c27eb
4
- data.tar.gz: 9f9b20456f61eae245a69cdcad9adc86f917711d14cd96cc1e8f8d3317caf038
3
+ metadata.gz: b34ac3de7b0a2195dd497f68fe24b52acf22469467cd4fdce5052fc3c893b703
4
+ data.tar.gz: c8979c98ca325f26d09722000ada76d205f1a5499fcaf77e0ee5b03fd4f00088
5
5
  SHA512:
6
- metadata.gz: ee5f0e5a66cf9a88d70d757e7b729636a4f600d9db8022e0eeabd1220ff80065e62221dca5941efe38fdf9cb059eef026fba663a1c045ff24008c98bf985dfd2
7
- data.tar.gz: 5894f8dfe7231d2a77e6a262f0422be1768613147d8a27cb565a08474dab95ec9026405f4fdbd76683ac7011271464361f98e7f3e65b65e358b81a97e9c4ba7d
6
+ metadata.gz: 91ba5899a87d934d7bd0b19a2fc18f0c6ea8dabd01bb093e558536afcf53a1568cbe72035b1c61e4cb071c7cdd4c2b9d8195fa7fe4d2d3f8bec91aae2ec99979
7
+ data.tar.gz: feef4f88bd22e8e3486e583fdab40d1b3e5e70590f704436579790f464afcf76de183ba49a57502d915fab2cc1358f0faaf215c3bf5759deb882879aad9b7b09
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 4.2.1
2
+ - Fixes performance regression introduced in 4.1.0 ([#70](https://github.com/logstash-plugins/logstash-filter-kv/issues/70))
3
+
1
4
  ## 4.2.0
2
5
  - Added `whitespace => strict` mode, which allows the parser to behave more predictably when input is known to avoid unnecessary whitespace.
3
6
  - Added error handling, which tags the event with `_kv_filter_error` if an exception is raised while handling an event instead of allowing the plugin to crash.
@@ -364,7 +364,9 @@ class LogStash::Filters::KV < LogStash::Filters::Base
364
364
 
365
365
  # a key is a _captured_ sequence of characters or escaped spaces before optional whitespace
366
366
  # and followed by either a `value_split`, a `field_split`, or EOF.
367
- key_pattern = unquoted_capture(value_split_pattern, field_split_pattern, eof)
367
+ key_pattern = (original_params.include?('value_split_pattern') || original_params.include?('field_split_pattern')) ?
368
+ unquoted_capture_until_pattern(value_split_pattern, field_split_pattern) :
369
+ unquoted_capture_until_charclass(@value_split + @field_split)
368
370
 
369
371
  value_pattern = begin
370
372
  # each component expression within value_pattern _must_ capture exactly once.
@@ -379,12 +381,14 @@ class LogStash::Filters::KV < LogStash::Filters::Base
379
381
  end
380
382
 
381
383
  # an unquoted value is a _captured_ sequence of characters or escaped spaces before a `field_split` or EOF.
382
- value_patterns << unquoted_capture(field_split_pattern, eof)
384
+ value_patterns << (original_params.include?('field_split_pattern') ?
385
+ unquoted_capture_until_pattern(field_split_pattern) :
386
+ unquoted_capture_until_charclass(@field_split))
383
387
 
384
388
  Regexp.union(value_patterns)
385
389
  end
386
390
 
387
- @scan_re = /#{key_pattern}#{value_split_pattern}#{value_pattern}#{Regexp::union(field_split_pattern, eof)}/
391
+ @scan_re = /#{key_pattern}#{value_split_pattern}#{value_pattern}?#{Regexp::union(field_split_pattern, eof)}/
388
392
  @value_split_re = value_split_pattern
389
393
 
390
394
  @logger.debug? && @logger.debug("KV scan regex", :regex => @scan_re.inspect)
@@ -446,7 +450,7 @@ class LogStash::Filters::KV < LogStash::Filters::Base
446
450
  close_pattern = /#{Regexp.quote(close_quote_sequence)}/
447
451
 
448
452
  # matches a sequence of zero or more characters are _not_ the `close_quote_sequence`
449
- quoted_value_pattern = unquoted_capture(close_pattern)
453
+ quoted_value_pattern = unquoted_capture_until_charclass(Regexp.quote(close_quote_sequence))
450
454
 
451
455
  /#{open_pattern}#{quoted_value_pattern}?#{close_pattern}/
452
456
  end
@@ -457,8 +461,19 @@ class LogStash::Filters::KV < LogStash::Filters::Base
457
461
  # @api private
458
462
  # @param *until_lookahead_patterns [Regexp]
459
463
  # @return [Regexp]
460
- def unquoted_capture(*until_lookahead_patterns)
461
- /((?:\\.|(?!#{Regexp::union(until_lookahead_patterns)}).)+)/
464
+ def unquoted_capture_until_pattern(*patterns)
465
+ pattern = patterns.size > 1 ? Regexp.union(patterns) : patterns.first
466
+ /((?:\\.|(?!#{pattern}).)+)/
467
+ end
468
+
469
+ # Helper function for generating *capturing* `Regexp` that will _efficiently_ match any sequence of characters
470
+ # that are either backslash-escaped or do _not_ belong to the given charclass.
471
+ #
472
+ # @api private
473
+ # @param charclass [String] characters to be injected directly into a regexp charclass; special characters must be pre-escaped.
474
+ # @return [Regexp]
475
+ def unquoted_capture_until_charclass(charclass)
476
+ /((?:\\.|[^#{charclass}])+)/
462
477
  end
463
478
 
464
479
  def transform(text, method)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-kv'
4
- s.version = '4.2.0'
4
+ s.version = '4.2.1'
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"
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.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement