Skip to content

Commit

Permalink
Prevent garbage from coming out of the LTSV parser
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Smith <[email protected]>
  • Loading branch information
threewordphrase committed Dec 25, 2019
1 parent 84df361 commit df8a22e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/fluent/plugin/parser_ltsv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def configure(conf)
def parse(text)
r = {}
text.split(@delimiter).each do |pair|
key, value = pair.split(@label_delimiter, 2)
r[key] = value
if pair.include? @label_delimiter
key, value = pair.split(@label_delimiter, 2)
r[key] = value
end
end
time, record = convert_values(parse_time(r), r)
yield time, record
Expand Down
15 changes: 15 additions & 0 deletions test/plugin/test_parser_labeled_tsv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ def test_parse_with_keep_time_key
end
end

def test_parse_and_reject_invalid_kv_pairs
parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::LabeledTSVParser)
parser.configure(
'delimiter' => ' ',
'label_delimiter' => '=',
)
text = 'A leading portion that is not LTSV : foo=bar baz=derp and a trailing portion'

expected = {'foo' => 'bar', 'baz' => 'derp'}
parser.instance.parse(text) do |time, record|
assert_equal expected, record
end

end

def test_parse_with_null_value_pattern
parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::LabeledTSVParser)
parser.configure(
Expand Down

0 comments on commit df8a22e

Please sign in to comment.