Skip to content

config: accept empty lines in quoted strings - #5448

Merged
kenhys merged 4 commits into
fluent:masterfrom
AkashKumar7902:agent/fix-multiline-empty-line
Aug 24, 2026
Merged

config: accept empty lines in quoted strings#5448
kenhys merged 4 commits into
fluent:masterfrom
AkashKumar7902:agent/fix-multiline-empty-line

Conversation

@AkashKumar7902

@AkashKumar7902 AkashKumar7902 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

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

What this PR does / why we need it:

The 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 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 thread lib/fluent/config/literal_parser.rb Outdated
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this PR will be closed in 7 days

@github-actions github-actions Bot added the stale label Aug 20, 2026
@Watson1978

Copy link
Copy Markdown
Contributor

#4691 (comment)
Of the three non-working examples, only the one using double quotes seems to be fixed.

Extract LINE_BREAK and LINE_CONTINUATION in LiteralParser and use them in
scan_double_quoted_string. Drop LINE_END_WITHOUT_SPACING_AND_COMMENT, which
no longer has any caller.

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
scan(/./) does not match a newline, so a single-quoted value spanning
multiple lines failed with "unexpected end of file". Scan line breaks
explicitly, as scan_double_quoted_string already does.

Unlike a double-quoted string, a backslash before a line break stays
literal here because single-quoted strings have no line continuation.

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
A physical line break inside a quoted value was stored verbatim, so the
same config text yielded a different value depending on whether the file
was saved with LF or CRLF. Ruby and YAML both normalize here.

An escaped "\r\n" still produces CRLF, and a lone CR is kept as before.

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
@Watson1978
Watson1978 force-pushed the agent/fix-multiline-empty-line branch from d2d1e02 to 6d3f550 Compare August 21, 2026 08:23
@Watson1978

Copy link
Copy Markdown
Contributor

I pushed three commits to this branch, please take a look.

Of the three non-working examples in the issue, only the double-quoted one was fixed, so I applied the same line break handling to scan_single_quoted_string. I also normalized CRLF to LF inside quoted strings, so that the same config text does not produce a different value depending on whether the file was saved with LF or CRLF. The last one extracts the line break patterns as named constants and drops LINE_END_WITHOUT_SPACING_AND_COMMENT, which no longer has any caller.

@Watson1978

Copy link
Copy Markdown
Contributor

@kenhys Can you review this PR?

@Watson1978 Watson1978 removed the stale label Aug 21, 2026
@Watson1978 Watson1978 added this to the v1.20.0 milestone Aug 21, 2026
@Watson1978 Watson1978 added the backport to v1.19 We will backport this fix to the LTS branch label Aug 21, 2026
@Watson1978
Watson1978 dismissed their stale review August 21, 2026 08:32

Because I fixed codes by myself.

@Watson1978 Watson1978 changed the title config: accept empty lines in double-quoted strings config: accept empty lines in quoted strings Aug 21, 2026

@kenhys kenhys 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.

LGTM

@kenhys

kenhys commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

nitpick: https://docs.fluentd.org/configuration/config-file#config-file-location

You can write multiline values for " quoted string, array and hash values.

It appears that it behaves a bit differently.

@Watson1978

Copy link
Copy Markdown
Contributor

Thanks

@kenhys
kenhys merged commit ed864f0 into fluent:master Aug 24, 2026
20 checks passed
mehrdadbn9 pushed a commit to mehrdadbn9/fluentd that referenced this pull request Aug 26, 2026
**Which issue(s) this PR fixes**: 
Fixes fluent#4691

**What this PR does / why we need it**: 

The 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 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 `dummy` → `record_transformer` → `stdout` and externally
parsed its emitted JSON as
`{"message":"seed","blank":"world\n\n","literal_backslash":"left\\\nright","continued":"leftright"}`.

---------

Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Co-authored-by: Shizuo Fujita <fujita@clear-code.com>
mehrdadbn9 pushed a commit to mehrdadbn9/fluentd that referenced this pull request Aug 26, 2026
**Which issue(s) this PR fixes**: 
Fixes fluent#4691

**What this PR does / why we need it**: 

The 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 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 `dummy` → `record_transformer` → `stdout` and externally
parsed its emitted JSON as
`{"message":"seed","blank":"world\n\n","literal_backslash":"left\\\nright","continued":"leftright"}`.

---------

Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Co-authored-by: Shizuo Fujita <fujita@clear-code.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch

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

3 participants