-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
time: handle >4-digit or negative years in MarshalJSON, UnmarshalJSON #4556
Labels
Comments
Quoting RFC 3339: There are many ways in which date and time values might appear in Internet protocols: this document focuses on just one common usage, viz. timestamps for Internet protocol events. This limited consideration has the following consequences: o All dates and times are assumed to be in the "current era", somewhere between 0000AD and 9999AD. |
Correct, RFC3339 is limited to 4 digit non-negative years. But dates as encoded in JSON often are not. The easiest way to get a Google API to give you a non-RFC3339 date is to insert a file using the Drive API with a modifiedDate outside of the RFC3339 range. Perhaps the API should have been written to disallow such dates, but it does not, and will happily return the values that you entered. It would not be such a big deal to fail non-RFC3339 dates with a parse error, except that through various means, you'll get giant JSON objects containing a listing of hundreds of files, and one invalid date will invalidate the entire listing. Worse, files with such dates can be caused to appear in your JSON responses by arbitrary third parties. (I can share a file with a crazy date with you, and cause you to get a parse error if you cannot understand it.) This is a kind of denial of service. |
Probably the easiest thing to do would be to define type Time struct { time.Time } func (t *Time) MarshalJSON ... func (t *Time) UnmarshalJSON ... and then users of the Google API Go package can get at the actual time by using .WhateverField.Time instead of .WhateverField. However, let's see if we can't get Google Drive to fix this first. It's going to break more than just Go. Russ |
Issue #7566 has been merged into this issue. |
Since this has come up again, more information: http://tools.ietf.org/html/rfc3339#section-1 o All dates and times are assumed to be in the "current era", somewhere between 0000AD and 9999AD. http://tools.ietf.org/html/rfc3339#section-5.6 date-fullyear = 4DIGIT full-date = date-fullyear "-" date-month "-" date-mday date-time = full-date "T" full-time That's very clear: years are 4 digits, not 5, and no minus sign. Returning an error from MarshalJSON and now MarshalText makes sure that the guarantee of RFC 3339-compliant output is met. time.Format does not return an error, and it cannot, because the input to time.Format is not some kind of enumerated constant but instead is a format specifier, a tiny program in a tiny language for printing times. The time.RFC3339 and time.RFC3339Nano constants are tiny programs in this tiny language that generate the closest approximation to RFC 3339 output that they can, but since the tiny language of time.Format has no concept of failing, the best they can do is generate these non-compliant results. This should not be construed to imply anything about what RFC 3339 requires. Again, RFC 3339 is very clear. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: