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

Prevent garbage from coming out of the LTSV parser #2748

Merged
merged 1 commit into from
Dec 25, 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
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