logstash-filter-xml 4.0.5 → 4.0.6

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: 6a7f6f6bc4d939e900e8f5979658c9456d00f4bb6b5ad463c1068637aeb308f1
4
- data.tar.gz: 5055ebdb1c13c410f1802f77b6681a7055b6c85a69b31b2561985673830b1f7d
3
+ metadata.gz: b00b3a1873a98c6e633b1b35bcd64a21eefe8f57fe3c28efcf4103c5a3855685
4
+ data.tar.gz: a363f65d3e9f2206221d076b8bfc6c2a4f560e952cb0415c4cea6eb5ab1762b6
5
5
  SHA512:
6
- metadata.gz: 7cd0c80bd580a55afa5edf461890b1cc6ba0f0747cfe7da4050a2237d562a2b4240286da3536d963fd10b57d28d59acf8edb498a59e09d745fd551c5bde6d478
7
- data.tar.gz: b965d484c29e2bd85aa7b27a07ed4469fc443737a1974126e1556931ac9f91860c5b1e5d9d671fcb039a6088ef497fa473b24a4a896241638996c9f565d2ae4e
6
+ metadata.gz: '099b6efdb5ad0ea40d18fa91c08a961e8a736cd12df8ee1a07e993c10f8e61dcd3227b7ceb274dc569f24a7417d905f08d607849bcee5005e54c17829d4ed123'
7
+ data.tar.gz: e8cede0fb4dc11a5b31aa4bc079ae4ab7b75f112b8acda4be47a582db0cf80120c84d62a40ee856c5264c50cb2bb46e55a0892b3d11e3c2eec97efa0572471a8
@@ -1,3 +1,6 @@
1
+ ## 4.0.6
2
+ - Fixed force_array behavior with nested elements [#57](https://github.com/logstash-plugins/logstash-filter-xml/pull/57)
3
+
1
4
  ## 4.0.5
2
5
  - Update gemspec summary
3
6
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
1
+ Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -156,21 +156,24 @@ class LogStash::Filters::Xml < LogStash::Filters::Base
156
156
  # String instead of a NodeSet. We normalize that here.
157
157
  normalized_nodeset = nodeset.kind_of?(Nokogiri::XML::NodeSet) ? nodeset : [nodeset]
158
158
 
159
+ # Initialize empty resultset
160
+ data = []
161
+
159
162
  normalized_nodeset.each do |value|
160
163
  # some XPath functions return empty arrays as string
161
- # TODO: (colin) the return statement here feels like a bug and should probably be a next ?
162
- return if value.is_a?(Array) && value.length == 0
164
+ next if value.is_a?(Array) && value.length == 0
163
165
 
164
166
  if value
165
167
  matched = true
166
- # TODO: (colin) this can probably be optimized to avoid the Event get/set at every loop iteration anf
167
- # the array should probably be created once, filled in the loop and set at after the loop but the return
168
- # statement above screws this strategy and is likely a bug anyway so I will not touch this until I can
169
- # deep a big deeper and verify there is a sufficient test harness to refactor this.
170
- data = event.get(xpath_dest) || []
171
168
  data << value.to_s
172
- event.set(xpath_dest, data)
173
169
  end
170
+
171
+ end
172
+ # set the destination attribute, if it's an array with a bigger size than one, leave as is. otherwise make it a string. added force_array param to provide same functionality as writing it in an xml target
173
+ if data.size == 1 && !@force_array
174
+ event.set(xpath_dest, data[0])
175
+ else
176
+ event.set(xpath_dest, data)
174
177
  end
175
178
  end
176
179
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-xml'
4
- s.version = '4.0.5'
4
+ s.version = '4.0.6'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Parses XML into fields"
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"
@@ -310,6 +310,26 @@ describe LogStash::Filters::Xml do
310
310
  end
311
311
  end
312
312
 
313
+ describe "parse disabling forcing with nested elements" do
314
+ config <<-CONFIG
315
+ filter {
316
+ xml {
317
+ source => "xmldata"
318
+ store_xml => "false"
319
+ force_array => "false"
320
+ xpath => [
321
+ "/element/field1/text()", "field1"
322
+ ]
323
+ }
324
+ }
325
+ CONFIG
326
+
327
+ # Single value
328
+ sample("xmldata" => '<element><field1>bbb</field1><field2>789</field2><field3>e3f<field3></element>') do
329
+ insist { subject.get("field1") } == "bbb"
330
+ end
331
+ end
332
+
313
333
  context "Using suppress_empty option" do
314
334
  describe "suppress_empty => false" do
315
335
  config <<-CONFIG
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.6.11
115
+ rubygems_version: 2.6.13
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Parses XML into fields