logstash-filter-mutate 1.0.1 → 1.0.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
  SHA1:
3
- metadata.gz: c6e8dbce3ff65a25dce65dbd8ae7751a404cd60a
4
- data.tar.gz: 9d2cfdaf0d3af46964281aa880c2f70dbf6768dd
3
+ metadata.gz: 2340f9a8f015a3c4f928f77ac33c833914dcc76f
4
+ data.tar.gz: a96cd73c174e946d1c9bc2e97b3b4a26e39776f5
5
5
  SHA512:
6
- metadata.gz: 2fe9cdfb16596fe8dc140a6b31f44a442de3ce76c30d5090f627bb3187c2c1f55b58da9af6b825710ec2470014417226e272c891fe08f595b354b080a00bcb17
7
- data.tar.gz: c1fed55596c84f174835abf6a5d7a44e7281c5d8d31aa523a017e9c3d5d348f0570c6e43930c6a76ab67a6dd1cb6cb83ea1fb061d2e1028d73343178f6945595
6
+ metadata.gz: 2488ab08c2dc09fc29a7a3e759a620e9944250b6922b7b5a06aa0c78f1bb7a0f3cc63dcf735cb6dcda486b9a62e6aa33137ddb5ec47cd7aae481f9b0ad1c61b4
7
+ data.tar.gz: dc9942e5c4c6cbb951dcb8d91c1805f1d54ee0ade7017a7458c2c066eb678eac4debe13826b7ac50df377ead42ab3fda69f800aac481264f7bd42f5e4608b63a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.2
2
+ - Fix for uppercase and lowercase fail when value is already desired case
3
+ - Modify tests to prove bug and verify fix.
4
+
1
5
  ## 1.0.1
2
6
  - Fix for uppercase and lowercase malfunction
3
7
  - Specific test to prove bug and fix.
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -342,11 +342,17 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
342
342
  def uppercase(event)
343
343
  @uppercase.each do |field|
344
344
  original = event[field]
345
+ # in certain cases JRuby returns a proxy wrapper of the event[field] value
346
+ # therefore we can't assume that we are modifying the actual value behind
347
+ # the key so read, modify and overwrite
345
348
  event[field] = case original
346
349
  when Array
347
- original.map(&:upcase!)
350
+ # can't map upcase! as it replaces an already upcase value with nil
351
+ # ["ABCDEF"].map(&:upcase!) => [nil]
352
+ original.map(&:upcase)
348
353
  when String
349
- original.upcase!
354
+ # nil means no change was made to the String
355
+ original.upcase! || original
350
356
  else
351
357
  @logger.debug("Can't uppercase something that isn't a string",
352
358
  :field => field, :value => original)
@@ -357,13 +363,14 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
357
363
 
358
364
  private
359
365
  def lowercase(event)
366
+ #see comments for #uppercase
360
367
  @lowercase.each do |field|
361
368
  original = event[field]
362
369
  event[field] = case original
363
370
  when Array
364
- original.map(&:downcase!)
371
+ original.map(&:downcase)
365
372
  when String
366
- original.downcase!
373
+ original.downcase! || original
367
374
  else
368
375
  @logger.debug("Can't lowercase something that isn't a string",
369
376
  :field => field, :value => original)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-mutate'
4
- s.version = '1.0.1'
4
+ s.version = '1.0.2'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "The mutate filter allows you to perform general mutations on fields. You can rename, remove, replace, and modify fields in your events."
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/plugin install gemname. This gem is not a stand-alone program"
@@ -34,7 +34,7 @@ describe LogStash::Filters::Mutate do
34
34
 
35
35
  describe 'MUTATE-33: multi stage with json, grok and mutate, Case mutation' do
36
36
  let(:event) do
37
- "{\"message\":\"hello WORLD\",\"examplefield\":\"PPQQRRSS\"}"
37
+ "{\"message\":\"hello WORLD\",\"lower1\":\"PPQQRRSS\",\"lower2\":\"pppqqq\"}"
38
38
  end
39
39
 
40
40
  let(:config) do
@@ -46,7 +46,7 @@ filter {
46
46
  singles => true
47
47
  }
48
48
  mutate {
49
- lowercase => [ "bar", "examplefield" ]
49
+ lowercase => [ "bar", "lower1", "lower2" ]
50
50
  }
51
51
  }
52
52
  CONFIG
@@ -57,9 +57,14 @@ CONFIG
57
57
  expect(result["bar"]).to eq('world')
58
58
  end
59
59
 
60
- it 'change case of the target, examplefield value is lowercase' do
60
+ it 'change case of the target, lower1 value is lowercase' do
61
61
  result = results.first
62
- expect(result["examplefield"]).to eq("ppqqrrss")
62
+ expect(result["lower1"]).to eq("ppqqrrss")
63
+ end
64
+
65
+ it 'change case of the target, lower2 value is lowercase' do
66
+ result = results.first
67
+ expect(result["lower2"]).to eq("pppqqq")
63
68
  end
64
69
 
65
70
  end
@@ -45,8 +45,8 @@ describe LogStash::Filters::Mutate do
45
45
  config <<-CONFIG
46
46
  filter {
47
47
  mutate {
48
- lowercase => "lowerme"
49
- uppercase => "upperme"
48
+ lowercase => ["lowerme","Lowerme", "lowerMe"]
49
+ uppercase => ["upperme", "Upperme", "upperMe"]
50
50
  convert => [ "intme", "integer", "floatme", "float" ]
51
51
  rename => [ "rename1", "rename2" ]
52
52
  replace => [ "replaceme", "hello world" ]
@@ -59,8 +59,12 @@ describe LogStash::Filters::Mutate do
59
59
  CONFIG
60
60
 
61
61
  event = {
62
- "lowerme" => [ "ExAmPlE" ],
63
- "upperme" => [ "ExAmPlE" ],
62
+ "lowerme" => "example",
63
+ "upperme" => "EXAMPLE",
64
+ "Lowerme" => "ExAmPlE",
65
+ "Upperme" => "ExAmPlE",
66
+ "lowerMe" => [ "ExAmPlE", "example" ],
67
+ "upperMe" => [ "ExAmPlE", "EXAMPLE" ],
64
68
  "intme" => [ "1234", "7890.4", "7.9" ],
65
69
  "floatme" => [ "1234.455" ],
66
70
  "rename1" => [ "hello world" ],
@@ -70,8 +74,12 @@ describe LogStash::Filters::Mutate do
70
74
  }
71
75
 
72
76
  sample event do
73
- expect(subject["lowerme"]).to eq ['example']
74
- expect(subject["upperme"]).to eq ['EXAMPLE']
77
+ expect(subject["lowerme"]).to eq 'example'
78
+ expect(subject["upperme"]).to eq 'EXAMPLE'
79
+ expect(subject["Lowerme"]).to eq 'example'
80
+ expect(subject["Upperme"]).to eq 'EXAMPLE'
81
+ expect(subject["lowerMe"]).to eq ['example', 'example']
82
+ expect(subject["upperMe"]).to eq ['EXAMPLE', 'EXAMPLE']
75
83
  expect(subject["intme"] ).to eq [1234, 7890, 7]
76
84
  expect(subject["floatme"]).to eq [1234.455]
77
85
  expect(subject).not_to include("rename1")
@@ -85,6 +93,28 @@ describe LogStash::Filters::Mutate do
85
93
  end
86
94
  end
87
95
 
96
+ describe "case handling of multibyte unicode strings will only change ASCII" do
97
+ config <<-CONFIG
98
+ filter {
99
+ mutate {
100
+ lowercase => ["lowerme"]
101
+ uppercase => ["upperme"]
102
+ }
103
+ }
104
+ CONFIG
105
+
106
+ event = {
107
+ "lowerme" => [ "АБВГД\0MMM", "こにちわ", "XyZółć", "NÎcË GÛŸ"],
108
+ "upperme" => [ "аБвгд\0mmm", "こにちわ", "xYzółć", "Nîcë gûÿ"],
109
+ }
110
+
111
+ sample event do
112
+ # ATM, only the ASCII characters will case change
113
+ expect(subject["lowerme"]).to eq [ "АБВГД\0mmm", "こにちわ", "xyzółć", "nÎcË gÛŸ"]
114
+ expect(subject["upperme"]).to eq [ "аБвгд\0MMM", "こにちわ", "XYZółć", "NîCë Gûÿ"]
115
+ end
116
+ end
117
+
88
118
  describe "remove multiple fields" do
89
119
  config '
90
120
  filter {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-mutate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-14 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core