Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexer accepts date with 1- to 3-digit year #441

Closed
moorereason opened this issue Sep 12, 2020 · 1 comment · Fixed by #443
Closed

Lexer accepts date with 1- to 3-digit year #441

moorereason opened this issue Sep 12, 2020 · 1 comment · Fixed by #443
Labels
bug Issues describing a bug in go-toml.

Comments

@moorereason
Copy link
Contributor

Describe the Bug

The existing dateRegexp accepts years with 1-3 digits. AFAIK, the TOML spec only allows 4-digit years.

To Reproduce

These should be pass, but they do:

diff --git a/lexer_test.go b/lexer_test.go
index 225a52a..e5ac952 100644
--- a/lexer_test.go
+++ b/lexer_test.go
@@ -350,6 +350,24 @@ func TestKeyEqualDate(t *testing.T) {
                {Position{1, 7}, tokenDate, "1979-05-27 07:32:00Z"},
                {Position{1, 27}, tokenEOF, ""},
        })
+       testFlow(t, "foo = 9-05-27 07:32:00Z", []token{
+               {Position{1, 1}, tokenKey, "foo"},
+               {Position{1, 5}, tokenEqual, "="},
+               {Position{1, 7}, tokenDate, "9-05-27 07:32:00Z"},
+               {Position{1, 24}, tokenEOF, ""},
+       })
+       testFlow(t, "foo = 79-05-27 07:32:00Z", []token{
+               {Position{1, 1}, tokenKey, "foo"},
+               {Position{1, 5}, tokenEqual, "="},
+               {Position{1, 7}, tokenDate, "79-05-27 07:32:00Z"},
+               {Position{1, 25}, tokenEOF, ""},
+       })
+       testFlow(t, "foo = 979-05-27 07:32:00Z", []token{
+               {Position{1, 1}, tokenKey, "foo"},
+               {Position{1, 5}, tokenEqual, "="},
+               {Position{1, 7}, tokenDate, "979-05-27 07:32:00Z"},
+               {Position{1, 26}, tokenEOF, ""},
+       })
 }

 func TestFloatEndingWithDot(t *testing.T) {

Expected Behavior

Only allow 4-digit years.

Versions

  • go-toml: 5c94d86
  • go version go1.15.2 linux/amd64
@pelletier
Copy link
Owner

Good catch! Thank you!

@pelletier pelletier added the bug Issues describing a bug in go-toml. label Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing a bug in go-toml.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants