Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed empty event set #59

Merged
merged 3 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/logstash/filters/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def filter(event)
if data.size == 1 && !@force_array
event.set(xpath_dest, data[0])
else
event.set(xpath_dest, data)
event.set(xpath_dest, data) unless data.nil? || data.empty?
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/filters/xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,21 @@
insist { subject.get("data") } == { 'x' => { 'content' => 'text1' }, 'y' => { 'a' => '2', 'content' => 'text2' } }
end
end
describe "does not set empty array event on failed xpath" do
config <<-CONFIG
filter {
xml {
source => "xmldata"
target => "data"
xpath => [ "//foo/text()","xpath_field" ]
}
}
CONFIG

sample("raw" => '<foobar></foobar>') do
insist { subject.get("tags") }.nil?
insist { subject.get("xpath_field")}.nil?
end
end
end
end