Skip to content
Open
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
9 changes: 4 additions & 5 deletions lib/fluent/config/literal_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ def scan_double_quoted_string
else
return string.join
end
elsif check(/[^"]#{LINE_END_WITHOUT_SPACING_AND_COMMENT}/o)
if s = check(/[^\\]#{LINE_END_WITHOUT_SPACING_AND_COMMENT}/o)
string << s
end
skip(/[^"]#{LINE_END_WITHOUT_SPACING_AND_COMMENT}/o)
elsif skip(/\\(?:\r\n|[\r\n])/)
next
elsif s = scan(/\r\n|[\r\n]/)
Comment on lines +101 to +103

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)

string << s
elsif s = scan(/\\./)
string << eval_escape_char(s[1,1])
elsif skip(/\#\{/)
Expand Down
1 change: 1 addition & 0 deletions test/config/test_config_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def parse_text(text)
end

test "support multiline string" do
assert_text_parsed_as(e('ROOT', '', {"k1" => "world\n\n"}), "k1 \"world\n\n\"")
assert_text_parsed_as(e('ROOT', '',
{"k1" => %[line1
line2]
Expand Down
7 changes: 7 additions & 0 deletions test/config/test_literal_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def test_falseX
test('"t') { assert_parse_error('"t') } # non-terminated quoted character
test("\"t\nt\"") { assert_text_parsed_as("t\nt", "\"t\nt\"" ) } # multiline string
test("\"t\\\nt\"") { assert_text_parsed_as("tt", "\"t\\\nt\"" ) } # multiline string
test("\"t\n\nt\"") { assert_text_parsed_as("t\n\nt", "\"t\n\nt\"") }
test("\"\nt\"") { assert_text_parsed_as("\nt", "\"\nt\"") }
test("\"t\\\\\nt\"") { assert_text_parsed_as("t\\\nt", "\"t\\\\\nt\"") }
test("\"t\r\nt\"") { assert_text_parsed_as("t\r\nt", "\"t\r\nt\"") }
test("\"t\\\r\nt\"") { assert_text_parsed_as("tt", "\"t\\\r\nt\"") }
test("\"t\n") { assert_parse_error("\"t\n") }
test("\"t\\\n") { assert_parse_error("\"t\\\n") }
test('t"') { assert_text_parsed_as('t"', 't"') }
test('"."') { assert_text_parsed_as('.', '"."') }
test('"*"') { assert_text_parsed_as('*', '"*"') }
Expand Down