From c1c4084e1d46a47f719bf7d7d0501a7566b11b39 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Tue, 14 Dec 2021 10:49:41 +0800 Subject: [PATCH] Cover the \n in flex. --- src/common/time/parser/datetime_scanner.lex | 2 +- .../time/parser/test/DateTimeParserTest.cpp | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/common/time/parser/datetime_scanner.lex b/src/common/time/parser/datetime_scanner.lex index 0e14cbb66ce..6df2f8321d4 100644 --- a/src/common/time/parser/datetime_scanner.lex +++ b/src/common/time/parser/datetime_scanner.lex @@ -59,7 +59,7 @@ R_BRACKET "]" return TokenType::TIME_ZONE_NAME; } -. { +\n|. { /** * Any other unmatched byte sequences will get us here, * including the non-ascii ones, which are negative diff --git a/src/common/time/parser/test/DateTimeParserTest.cpp b/src/common/time/parser/test/DateTimeParserTest.cpp index 44acb835a14..939441b48b4 100644 --- a/src/common/time/parser/test/DateTimeParserTest.cpp +++ b/src/common/time/parser/test/DateTimeParserTest.cpp @@ -83,6 +83,16 @@ TEST(DatetimeReader, DateTimeFailed) { auto result = parser.readDatetime("2019-01-03T22:22:3.2333x"); EXPECT_FALSE(result.ok()) << result.value(); } + { + auto parser = time::DatetimeReader::makeDateTimeReader(); + auto result = parser.readDatetime("2019-01-03T22:22:3.2333\n"); + EXPECT_FALSE(result.ok()) << result.value(); + } + { + auto parser = time::DatetimeReader::makeDateTimeReader(); + auto result = parser.readDatetime("\t2019-01-03T22:22:3.2333"); + EXPECT_FALSE(result.ok()) << result.value(); + } // not ending delimiter { auto parser = time::DatetimeReader::makeDateTimeReader(); @@ -150,6 +160,16 @@ TEST(DatetimeReader, DateFailed) { auto result = parser.readDate("2019-01-03*"); EXPECT_FALSE(result.ok()) << result.value(); } + { + auto parser = time::DatetimeReader::makeDateReader(); + auto result = parser.readDate("2019-01-03\n"); + EXPECT_FALSE(result.ok()) << result.value(); + } + { + auto parser = time::DatetimeReader::makeDateReader(); + auto result = parser.readDate("\t2019-01-03"); + EXPECT_FALSE(result.ok()) << result.value(); + } // extra components { auto parser = time::DatetimeReader::makeDateReader(); @@ -227,6 +247,16 @@ TEST(DatetimeReader, TimeFailed) { auto result = parser.readTime("22:22:3.2333x"); EXPECT_FALSE(result.ok()) << result.value(); } + { + auto parser = time::DatetimeReader::makeTimeReader(); + auto result = parser.readTime("22:22:3.2333\n"); + EXPECT_FALSE(result.ok()) << result.value(); + } + { + auto parser = time::DatetimeReader::makeTimeReader(); + auto result = parser.readTime("\t22:22:3.2333\n"); + EXPECT_FALSE(result.ok()) << result.value(); + } // extra components { auto parser = time::DatetimeReader::makeTimeReader();