From dd44876e6b4d154594886fb84c44e2c9b60db7b2 Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Tue, 18 May 2021 12:27:45 +0800 Subject: [PATCH] timeFormatCheck add new test cases --- advisor/heuristic.go | 2 +- advisor/heuristic_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/advisor/heuristic.go b/advisor/heuristic.go index e03ef11..e781ac1 100644 --- a/advisor/heuristic.go +++ b/advisor/heuristic.go @@ -376,7 +376,7 @@ func timeFormatCheck(t string) bool { // 不允许为空,但允许时间前后有空格 t = strings.TrimSpace(t) // 仅允许 数字、减号、冒号、空格 - allowChars := regexp.MustCompile(`^[\-0-9: ]+$`) + allowChars := regexp.MustCompile(`^[\-0-9:. ]+$`) return allowChars.MatchString(t) } diff --git a/advisor/heuristic_test.go b/advisor/heuristic_test.go index 78b3943..bbe3517 100644 --- a/advisor/heuristic_test.go +++ b/advisor/heuristic_test.go @@ -156,6 +156,9 @@ func TestRuleEqualLike(t *testing.T) { func TestTimeFormatError(t *testing.T) { rightTimes := []string{ `2020-01-01`, + `2020-01-01 23:59:59`, + `2020-01-01 23:59:59.0`, // 0ms + `2020-01-01 23:59:59.123`, // 123ms } for _, rt := range rightTimes { if !timeFormatCheck(rt) { -- GitLab