Repository navigation
parser_regexp: handle UTF-8 binary input - #5710
Watson1978 merged 4 commits into
Conversation
Signed-off-by: Sanket Patel <sanpatel323@gmail.com>
Signed-off-by: Sanket Patel <sanpatel323@gmail.com>
Signed-off-by: Sanket Patel <sanpatel323@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the fix. The parser change fixes #5691. Valid UTF-8 lines now match a UTF-8 expression, so the other lines and the connection are kept. The new tests for this case fail on master and pass with this change.
I have one request. Please remove the in_tcp change from this PR, because #5640 changes the same code for #5629. See the inline comment.
Signed-off-by: Sanket Patel <sanpatel323@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the update. This addresses my previous review. lib/fluent/plugin/in_tcp.rb matches master again, and the new parser test covers both invalid bytes in binary input and input tagged with another encoding. I confirmed that the new tests for valid UTF-8 input fail on master and pass with this change, in both emit modes for in_tcp.
#5640 was closed, so I opened #5711 for the in_tcp side. I tested both PRs together locally. They merge cleanly, the tests in both changed test files pass, and a line with invalid UTF-8 bytes no longer closes the connection.
LGTM.
in_tail passes lines to the parser as ASCII-8BIT strings when
`encoding` is not set. When format_firstline was a UTF-8 regexp, such
as one with \p{Alpha}, MultilineParser#firstline? raised
Encoding::CompatibilityError at the first non-ASCII line. The error
escaped from in_tail's parse_multilines, so in_tail read the same lines
again on every notification and never moved past them. When format1
was a UTF-8 regexp, MultilineRegexpParser#parse raised the same error
and in_tail dropped the whole multiline event.
Apply the retry added in fluent#5710 in MultilineRegexpParser#parse and
MultilineParser#firstline? too. The check and the UTF-8 copy move into
RegexpParser.utf8_text_for_retry, which runs only after the error, so
matching without the error costs the same as before. A binary string
with valid UTF-8 bytes is matched again as UTF-8.
Other incompatible input still raises Encoding::CompatibilityError.
Fixes fluent#5714
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Rajyavardhan <rajyavardhansing2003@gmail.com>
…5717) in_tail passes lines to the parser as ASCII-8BIT strings when `encoding` is not set. When format_firstline was a UTF-8 regexp, such as one with \p{Alpha}, MultilineParser#firstline? raised Encoding::CompatibilityError at the first non-ASCII line. The error escaped from in_tail's parse_multilines, so in_tail read the same lines again on every notification and never moved past them. When format1 was a UTF-8 regexp, MultilineRegexpParser#parse raised the same error and in_tail dropped the whole multiline event. Apply the retry added in #5710 in MultilineRegexpParser#parse and MultilineParser#firstline? too. The check and the UTF-8 copy move into RegexpParser.utf8_text_for_retry, which runs only after the error, so matching without the error costs the same as before. A binary string with valid UTF-8 bytes is matched again as UTF-8. Other incompatible input still raises Encoding::CompatibilityError. Fixes #5714 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Rajyavardhan <rajyavardhansing2003@gmail.com>
Which issue(s) this PR fixes:
Fixes #5691
What this PR does / why we need it:
in_tcppasses socket lines to parsers as ASCII-8BIT strings. A UTF-8-only regexp — including one written in an ASCII-only configuration with\p{Alpha}or a Unicode escape — raisesEncoding::CompatibilityErrorfor valid non-ASCII UTF-8 input. The exception escapes parsing, so the server helper closes the connection and the other lines in the same read are lost.This PR retries the regexp match with a UTF-8 copy when the regexp is UTF-8, the input is binary, and the bytes are valid UTF-8. Binary input whose bytes are not valid UTF-8, and input tagged with another encoding, still raise
Encoding::CompatibilityErroras before.Tests cover UTF-8 regexp matching of binary input, both error paths, and
in_tcpin batch and single-emit modes with several lines in one read followed by another write on the same connection.Tests run in the
ruby:3.4-slimDocker image on Linux:bundle exec rake test TEST=test/plugin/test_in_tcp.rb: 44 tests, 89 assertions, 100% passedbundle exec rake test TEST=test/plugin/test_parser_regexp.rb: 22 tests, 44 assertions, 100% passedrubocop: 474 files inspected, no offenses detectedDocs Changes:
None.
Release Note:
parser_regexp: parse valid UTF-8 messages passed as binary strings with UTF-8 regexps.