Fix for LOGSTASH-733: allow whitespace in value when using field pipe-delimiter

This commit is contained in:
Wiibaa 2012-12-21 11:18:26 +01:00
parent e7e9a70840
commit e0da16cbf7
2 changed files with 18 additions and 3 deletions

View file

@ -33,9 +33,10 @@ class LogStash::Filters::KV < LogStash::Filters::Base
#
# Example, to split out the args from a string such as
# '?pin=12345~0&d=123&e=foo@bar.com&oq=bobo&ss=12345':
#
#
# Default to space character for backward compatibility
# filter { kv { field_split => "&?" } }
config :field_split, :validate => :string, :default => ''
config :field_split, :validate => :string, :default => ' '
# A string of characters to use as delimiters for identifying key-value relations.
@ -95,7 +96,7 @@ class LogStash::Filters::KV < LogStash::Filters::Base
if !event =~ /[@field_split]/
return kv_keys
end
scan_re = Regexp.new("([^ "+@field_split+@value_split+"]+)["+@value_split+"](?:\"([^\""+@field_split+"]+)\"|'([^'"+@field_split+"]+)'|([^ "+@field_split+"]+))")
scan_re = Regexp.new("([^"+@field_split+@value_split+"]+)["+@value_split+"](?:\"([^\"]+)\"|'([^']+)'|([^"+@field_split+"]+))")
text.scan(scan_re) do |key, v1, v2, v3|
value = v1 || v2 || v3
if !@trim.nil?

View file

@ -61,6 +61,20 @@ describe LogStash::Filters::KV do
end
describe "delimited fields should override space default (reported by LOGSTASH-733)" do
config <<-CONFIG
filter {
kv { field_split => "|" }
}
CONFIG
sample "field1=test|field2=another test|field3=test3" do
insist { subject["field1"] } == "test"
insist { subject["field2"] } == "another test"
insist { subject["field3"] } == "test3"
end
end
describe "test prefix" do
config <<-CONFIG
filter {