if ind := strings.IndexAny(p.s, "+-"); ind != -1 && len(p.s) >= ind+5 {
date = p.s[:ind+5]
p.s = p.s[ind+5:]
- } else if ind := strings.Index(p.s, "T"); ind != -1 && len(p.s) >= ind+1 {
- // The last letter T of the obsolete time zone is checked when no standard time zone is found.
- // If T is misplaced, the date to parse is garbage.
- date = p.s[:ind+1]
- p.s = p.s[ind+1:]
+ } else {
+ ind := strings.Index(p.s, "T")
+ if ind == 0 {
+ // In this case we have the following date formats:
+ // * Thu, 20 Nov 1997 09:55:06 MDT
+ // * Thu, 20 Nov 1997 09:55:06 MDT (MDT)
+ // * Thu, 20 Nov 1997 09:55:06 MDT (This comment)
+ ind = strings.Index(p.s[1:], "T")
+ if ind != -1 {
+ ind++
+ }
+ }
+
+ if ind != -1 && len(p.s) >= ind+5 {
+ // The last letter T of the obsolete time zone is checked when no standard time zone is found.
+ // If T is misplaced, the date to parse is garbage.
+ date = p.s[:ind+1]
+ p.s = p.s[ind+1:]
+ }
}
if !p.skipCFWS() {
return time.Time{}, errors.New("mail: misformatted parenthetical comment")
"Fri, 21 Nov 1997 09:55:06 -0600 (MDT)",
time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("", -6*60*60)),
},
+ {
+ "Thu, 20 Nov 1997 09:55:06 -0600 (MDT)",
+ time.Date(1997, 11, 20, 9, 55, 6, 0, time.FixedZone("", -6*60*60)),
+ },
+ {
+ "Thu, 20 Nov 1997 09:55:06 MDT (MDT)",
+ time.Date(1997, 11, 20, 9, 55, 6, 0, time.FixedZone("MDT", 0)),
+ },
+ {
+ "Fri, 21 Nov 1997 09:55:06 +1300 (TOT)",
+ time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("", +13*60*60)),
+ },
}
for _, test := range tests {
hdr := Header{
time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("", -6*60*60)),
false,
},
+ // Ensure that the presence of "T" in the date
+ // doesn't trip out ParseDate, as per issue 39260.
+ {
+ "Tue, 26 May 2020 14:04:40 GMT",
+ time.Date(2020, 05, 26, 14, 04, 40, 0, time.UTC),
+ true,
+ },
+ {
+ "Tue, 26 May 2020 14:04:40 UT",
+ time.Date(2020, 05, 26, 14, 04, 40, 0, time.UTC),
+ false,
+ },
+ {
+ "Thu, 21 May 2020 14:04:40 UT",
+ time.Date(2020, 05, 21, 14, 04, 40, 0, time.UTC),
+ false,
+ },
+ {
+ "Thu, 21 May 2020 14:04:40 UTC",
+ time.Date(2020, 05, 21, 14, 04, 40, 0, time.UTC),
+ true,
+ },
+ {
+ "Fri, 21 Nov 1997 09:55:06 MDT (MDT)",
+ time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("MDT", 0)),
+ true,
+ },
}
for _, test := range tests {
hdr := Header{