Fix date lexer to only support 4-digit year (#443)

Fixes #441
This commit is contained in:
Cameron Moore
2020-09-12 17:04:04 -05:00
committed by GitHub
parent 65ca806488
commit a7448fe8de
2 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -788,7 +788,7 @@ func init() {
// 1979-05-27
// 07:32:00
// 00:32:00.999999
dateRegexp = regexp.MustCompile(`^(?:\d{1,4}-\d{2}-\d{2})?(?:[T ]?\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})?)?`)
dateRegexp = regexp.MustCompile(`^(?:\d{4}-\d{2}-\d{2})?(?:[T ]?\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})?)?`)
}
// Entry point
+10 -4
View File
@@ -2,6 +2,7 @@ package toml
import (
"reflect"
"strings"
"testing"
)
@@ -313,16 +314,21 @@ func TestDateRegexp(t *testing.T) {
"date-no-tz": "1979-05-27",
"time-no-tz": "07:32:00",
"time-no-tz-nano": "00:32:00.999999",
"err:date-1year": "9-05-27",
"err:date-2year": "79-05-27",
"err:date-3year": "979-05-27",
}
for name, value := range cases {
if dateRegexp.FindString(value) == "" {
res := dateRegexp.FindString(value)
if strings.HasPrefix(name, "err:") {
if res != "" {
t.Error("failed date regexp test", name)
}
} else if res == "" {
t.Error("failed date regexp test", name)
}
}
if dateRegexp.FindString("1979-05-27 07:32:00Z") == "" {
t.Error("space delimiter lexing")
}
}
func TestKeyEqualDate(t *testing.T) {