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

function/stdlib: Use local RFC3339 parser #152

Merged
merged 1 commit into from
Jan 19, 2023
Merged

Conversation

apparentlymart
Copy link
Collaborator

The Go time package's interpretation of RFC3339 has historically been too liberal to properly meet the specification due to reliance on the "parse by example" approach taken by time.Parse.

There was a custom strict RFC3339 parser added during the Go 1.20 development period but that was removed just before release due to backward compatibility concerns.

Since cty's goal is to only accept valid RFC3339 and its use of the Go standard library to achieve that was always an implementation detail, here we'll now just inline a slightly similified version of the strict RFC3339 parser that was briefly in stdlib and use that.

Although a variation of this strict parser will probably land in Go stdlib again eventually, the goal here is to decouple cty's behavior from the Go stdlib behavior so it will be consistent regardless of what version of Go the application was compiled with and regardless of any GODEBUG flags the Go team might add to help mitigate compatibility problems in other applications.

Background details on the Go stdlib changes that prompted this are over in golang/go#57912.

Note: If anyone was previously passing slightly-invalid RFC3339 strings to the formatdate function, or to any other function which expects an RFC3339 timestamp, those will now be rejected as invalid and will need to be fixed. The out-of-spec parsing was a defect rather than a feature and so I don't consider this to be a breaking change to the contract of those functions.

The Go "time" package's interpretation of RFC3339 has historically been
too liberal to properly meet the specification due to reliance on the
"parse by example" approach taken by time.Parse.

There was a custom strict RFC3339 parser added during the Go 1.20
development period but that was removed just before release due to
backward compatibility concerns.

Since cty's goal is to only accept valid RFC3339 and its use of the Go
standard library to achieve that was always an implementation detail, here
we'll now just inline a slightly similified version of the strict RFC3339
parser that was briefly in stdlib and use that.

Although a variation of this strict parser will probably land in stdlib
again eventually, the goal here is to decouple cty's behavior from the Go
stdlib behavior so it will be consistent regardless of what version of Go
the application was compiled with and regardless of any weirdo GODEBUG
flags the Go team might add to help mitigate compatibility problems in
other applications.
@apparentlymart apparentlymart merged commit e8055bc into main Jan 19, 2023
@apparentlymart apparentlymart deleted the b-timestamp-parsing branch January 19, 2023 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant