Fix for LOGSTASH-624: allow escaped spaces in key or value

This commit is contained in:
Wiibaa 2012-12-21 13:15:54 +01:00
parent e0da16cbf7
commit e0b09f075e
2 changed files with 14 additions and 1 deletions

View file

@ -96,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+"]+))")
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

@ -24,6 +24,19 @@ describe LogStash::Filters::KV do
end
describe "LOGSTASH-624: allow escaped space in key or value " do
config <<-CONFIG
filter {
kv { value_split => ':' }
}
CONFIG
sample 'IKE:=Quick\ Mode\ completion IKE\ IDs:=subnet:\ x.x.x.x\ (mask=\ 255.255.255.254)\ and\ host:\ y.y.y.y' do
insist { subject["IKE"] } == '=Quick\ Mode\ completion'
insist { subject['IKE\ IDs'] } == '=subnet:\ x.x.x.x\ (mask=\ 255.255.255.254)\ and\ host:\ y.y.y.y'
end
end
describe "test value_split" do
config <<-CONFIG
filter {