-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Parser incorrectly parses years in some cases #162
Comments
After a quick discussion, this behavior is correct as intended on time's end — the century will not be assumed. Apparently this originates from Cloudflare, which isn't actually following the spec (emphasis mine)
The first part of that doesn't actually specify what should happen when encountering a two-digit year, though I can't find anything along those lines in any RFC. As such, I think it's best to follow browsers' behavior. Apparently Chrome uses the following code (@except can you provide a source?) // Normalize the year to expand abbreviated years to the full year.
if (exploded.year >= 69 && exploded.year <= 99)
exploded.year += 1900;
if (exploded.year >= 0 && exploded.year <= 68)
exploded.year += 2000; This essentially assumes the year is between 1969 and 2068 inclusive. Unfortunately, the only way to adjust the year is to fully reconstruct a |
Source to where Chromium corrects two-digit based years. |
For the record: I have just submitted a request to Cloudflare. Regardless, this crate's behavior is also not spec compliant. |
Firefox uses PR_ParseTimeString (PR_ParseTimeStringToExplodedTime) which does something similar when parsing. year = n1;
if (year < 70) {
year += 2000;
}
else if (year < 100) {
year += 1900;
} WebKit using parseExpiresMS (WTF::parseDateFromNullTerminatedCharacter) also parses slightly differently. if (year) {
int yearValue = year.value();
if (yearValue >= 0 && yearValue < 100) {
if (yearValue < 50)
yearValue += 2000;
else
yearValue += 1900;
}
year = yearValue;
} |
Thank you for the input, all! |
Consider the following Set-Cookie header -
foo=bar; expires=Thu, 10-Sep-20 20:00:00 GMT;
This should be parsed as
2020-09-10 20:00 +0
however expires returns0020-09-10 20:00 +0
The text was updated successfully, but these errors were encountered: