Skip to content

Commit a570d34

Browse files
committed
fix. date validator will reject 00 in day part.
the `validateDate` impl only checks the overflow of day part, which allows input like DATE("2024-07-00"). this will lead to error in reading process.
1 parent fee249b commit a570d34

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/common/time/TimeUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class TimeUtils {
5050
if ((p[date.month] - p[date.month - 1]) < date.day) {
5151
return Status::Error("`%s' is not a valid date.", date.toString().c_str());
5252
}
53+
if (UNLIKELY(0 == date.day)) {
54+
return Status::Error("`%s' is not a valid date since invalid day.",
55+
date.toString().c_str());
56+
}
5357
return Status::OK();
5458
}
5559

src/common/time/parser/test/DateTimeParserTest.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ TEST(DatetimeReader, DateTimeFailed) {
178178
auto result = parser.readDatetime("1999-01-32T22:22:3.2333");
179179
EXPECT_FALSE(result.ok()) << result.value();
180180
}
181+
{
182+
auto parser = time::DatetimeReader();
183+
auto result = parser.readDatetime("1999-00-03T12:34:56.2333");
184+
EXPECT_FALSE(result.ok()) << result.value();
185+
}
186+
{
187+
auto parser = time::DatetimeReader();
188+
auto result = parser.readDatetime("1999-01-00T22:00:03.2333");
189+
EXPECT_FALSE(result.ok()) << result.value();
190+
}
191+
{
192+
auto parser = time::DatetimeReader();
193+
auto result = parser.readDatetime("1999-00-00T22:22:05.2333");
194+
EXPECT_FALSE(result.ok()) << result.value();
195+
}
181196
}
182197

183198
TEST(DatetimeReader, Date) {
@@ -278,6 +293,21 @@ TEST(DatetimeReader, DateFailed) {
278293
auto result = parser.readDate("1999-01-32");
279294
EXPECT_FALSE(result.ok()) << result.value();
280295
}
296+
{
297+
auto parser = time::DatetimeReader();
298+
auto result = parser.readDate("1999-00-03");
299+
EXPECT_FALSE(result.ok()) << result.value();
300+
}
301+
{
302+
auto parser = time::DatetimeReader();
303+
auto result = parser.readDate("1999-01-00");
304+
EXPECT_FALSE(result.ok()) << result.value();
305+
}
306+
{
307+
auto parser = time::DatetimeReader();
308+
auto result = parser.readDate("1999-00-00");
309+
EXPECT_FALSE(result.ok()) << result.value();
310+
}
281311
}
282312

283313
TEST(DatetimeReader, Time) {

0 commit comments

Comments
 (0)