diff --git a/lib/fluent/config/literal_parser.rb b/lib/fluent/config/literal_parser.rb index 6362d5a52c..53d921b78c 100644 --- a/lib/fluent/config/literal_parser.rb +++ b/lib/fluent/config/literal_parser.rb @@ -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]/) + string << s elsif s = scan(/\\./) string << eval_escape_char(s[1,1]) elsif skip(/\#\{/) diff --git a/test/config/test_config_parser.rb b/test/config/test_config_parser.rb index fe29028ef7..00bbf895b8 100644 --- a/test/config/test_config_parser.rb +++ b/test/config/test_config_parser.rb @@ -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] diff --git a/test/config/test_literal_parser.rb b/test/config/test_literal_parser.rb index 275e468e3f..e993b8696d 100644 --- a/test/config/test_literal_parser.rb +++ b/test/config/test_literal_parser.rb @@ -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('*', '"*"') }