Skip to content
Closed
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
4 changes: 3 additions & 1 deletion lib/fluent/plugin/parser_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class SyslogParser < Parser
RFC3164_CAPTURES = RFC3164_WITHOUT_TIME_AND_PRI_REGEXP.names.freeze
RFC3164_PRI_REGEXP = /\A<(?<pri>[0-9]{1,3})>/

RFC5424_WITHOUT_TIME_AND_PRI_REGEXP = /(?<host>[!-~]{1,255}) (?<ident>[!-~]{1,48}) (?<pid>[!-~]{1,128}) (?<msgid>[!-~]{1,32}) (?<extradata>(?:\-|(?:\[.*?(?<!\\)\])))(?: (?<message>.+))?\z/m
# \G anchors the match at the position given to Regexp#match, so a header
# that doesn't match there is rejected instead of matched further on.
RFC5424_WITHOUT_TIME_AND_PRI_REGEXP = /\G(?<host>[!-~]{1,255}) (?<ident>[!-~]{1,48}) (?<pid>[!-~]{1,128}) (?<msgid>[!-~]{1,32}) (?<extradata>(?:\-|(?:\[.*?(?<!\\)\])))(?: (?<message>.+))?\z/m
RFC5424_CAPTURES = RFC5424_WITHOUT_TIME_AND_PRI_REGEXP.names.freeze
RFC5424_PRI_REGEXP = /\A<(?<pri>\d{1,3})>\d\d{0,2}\s/

Expand Down
13 changes: 13 additions & 0 deletions test/plugin/test_parser_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,19 @@ def test_parse_with_rfc5424_message_includes_right_bracket(param)
end
end

data(
'non-ASCII hostname' => '<14>1 2026-04-25T16:43:29Z hôst app 123 ID - msg',
'header fields after a line break' => "<14>1 2026-04-25T16:43:29Z first line\nhost app 123 ID - second line",
)
def test_parse_with_rfc5424_regexp_does_not_skip_unmatched_header(text)
@parser.configure(
'message_format' => 'rfc5424',
'with_priority' => true,
'parser_engine' => 'regexp'
)
assert_input_rejected(text, :rejects)
end

data(
'regexp/with message' => ['regexp', '[x@1 a="b\] c"]', 'msg'],
'string/with message' => ['string', '[x@1 a="b\] c"]', 'msg'],
Expand Down