Skip to content

config: accept empty lines in double-quoted strings#5448

Open
AkashKumar7902 wants to merge 1 commit into
fluent:masterfrom
AkashKumar7902:agent/fix-multiline-empty-line
Open

config: accept empty lines in double-quoted strings#5448
AkashKumar7902 wants to merge 1 commit into
fluent:masterfrom
AkashKumar7902:agent/fix-multiline-empty-line

Conversation

@AkashKumar7902

Copy link
Copy Markdown

Which issue(s) this PR fixes:
Fixes #4691

What this PR does / why we need it:

Double-quoted configuration values previously handled a physical line ending together with its preceding character. When the parser was already positioned at a line ending—such as on an empty line or after an escaped literal backslash—it instead reported an unexpected end of file.

Handle backslash line continuations and preserved line endings explicitly. This accepts empty lines, preserves LF and CRLF, and retains the existing single-backslash continuation behavior.

Docs Changes:

None. The existing multiline-string documentation already describes the intended behavior.

Release Note:

config: accept empty lines in double-quoted strings.

Testing:

Automated:

  • bundle exec rake test TEST=test/config/test_literal_parser.rb — 220 tests, 223 assertions, 0 failures, 0 errors
  • TEST_ENV_NUMBER=focus4691 bundle exec rake test TEST=test/config/test_config_parser.rb — 56 tests, 106 assertions, 0 failures, 0 errors
  • bundle exec rake test (two independent runs) — 4,343 tests, 15,829 and 15,830 assertions respectively; 0 failures, 0 errors, 3 pendings, and 36 omissions in both
  • rubocop — 459 files inspected, no offenses
  • ruby -c for all three changed Ruby files and git diff --check

Manual (Ruby 4.0.6):

  • Built and separately installed gems from baseline f380d996bc828b5cd488b578018c06826ebcbf7e and candidate 7d017869a55e179da4d195806f26d33dc485fc9d.
  • The baseline built gem rejected the reproducing configuration with a false unexpected-EOF error; the candidate built gem accepted it with fluentd --dry-run; a genuinely unterminated double-quoted value remained rejected.
  • Ran the candidate built gem as a separate fluentd --no-supervisor process through dummyrecord_transformerstdout and externally parsed its emitted JSON as {"message":"seed","blank":"world\n\n","literal_backslash":"left\\\nright","continued":"leftright"}.

Handle physical line endings independently from preceding characters so a blank line or an escaped literal backslash before a newline does not look like EOF. Preserve CRLF as a unit for line continuation.

Signed-off-by: Akash Kumar <meakash7902@gmail.com>
@AkashKumar7902
AkashKumar7902 marked this pull request as ready for review July 19, 2026 15:56

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix.

The token-based handling of line breaks reads much more clearly than the old [^"]-plus-line-end pairing. The small follow-up suggestions on the same change.

Comment on lines +101 to +103
elsif skip(/\\(?:\r\n|[\r\n])/)
next
elsif s = scan(/\r\n|[\r\n]/)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove now unused constant in

LINE_END_WITHOUT_SPACING_AND_COMMENT = /(?:\z|[\r\n])/

And, add constants instead, like

  # A physical line break (LF, CR, or CRLF) inside a double-quoted string.
  # It is preserved as-is in the resulting value.
  LINE_BREAK = /\r\n|[\r\n]/
  # A backslash immediately followed by a physical line break.
  # It works as a line continuation, so both are stripped from the value.
  LINE_CONTINUATION = /\\#{LINE_BREAK}/o

and use them

          elsif skip(LINE_CONTINUATION)
            next
          elsif s = scan(LINE_BREAK)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quoted string parser reports end of file when encountering an empty line

2 participants