aboutsummaryrefslogtreecommitdiff
path: root/src/net/mail
diff options
context:
space:
mode:
authorKatie Hockman <katie@golang.org>2020-12-14 10:03:05 -0500
committerKatie Hockman <katie@golang.org>2020-12-14 10:06:13 -0500
commit0345ede87ee12698988973884cfc0fd3d499dffd (patch)
tree7123cff141ee5661208d2f5f437b8f5252ac7f6a /src/net/mail
parent4651d6b267818b0e0d128a5443289717c4bb8cbc (diff)
parent0a02371b0576964e81c3b40d328db9a3ef3b031b (diff)
downloadgo-0345ede87ee12698988973884cfc0fd3d499dffd.tar.xz
[dev.fuzz] all: merge master into dev.fuzz
Change-Id: I5d8c8329ccc9d747bd81ade6b1cb7cb8ae2e94b2
Diffstat (limited to 'src/net/mail')
-rw-r--r--src/net/mail/example_test.go4
-rw-r--r--src/net/mail/message.go24
-rw-r--r--src/net/mail/message_test.go44
3 files changed, 62 insertions, 10 deletions
diff --git a/src/net/mail/example_test.go b/src/net/mail/example_test.go
index c3365642aa..d325dc791f 100644
--- a/src/net/mail/example_test.go
+++ b/src/net/mail/example_test.go
@@ -6,7 +6,7 @@ package mail_test
import (
"fmt"
- "io/ioutil"
+ "io"
"log"
"net/mail"
"strings"
@@ -62,7 +62,7 @@ Message body
fmt.Println("To:", header.Get("To"))
fmt.Println("Subject:", header.Get("Subject"))
- body, err := ioutil.ReadAll(m.Body)
+ body, err := io.ReadAll(m.Body)
if err != nil {
log.Fatal(err)
}
diff --git a/src/net/mail/message.go b/src/net/mail/message.go
index 09fb794005..47bbf6ca97 100644
--- a/src/net/mail/message.go
+++ b/src/net/mail/message.go
@@ -112,11 +112,25 @@ func ParseDate(date string) (time.Time, error) {
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")
diff --git a/src/net/mail/message_test.go b/src/net/mail/message_test.go
index 67e3643aeb..0daa3d6c63 100644
--- a/src/net/mail/message_test.go
+++ b/src/net/mail/message_test.go
@@ -7,7 +7,6 @@ package mail
import (
"bytes"
"io"
- "io/ioutil"
"mime"
"reflect"
"strings"
@@ -53,7 +52,7 @@ func TestParsing(t *testing.T) {
t.Errorf("test #%d: Incorrectly parsed message header.\nGot:\n%+v\nWant:\n%+v",
i, msg.Header, test.header)
}
- body, err := ioutil.ReadAll(msg.Body)
+ body, err := io.ReadAll(msg.Body)
if err != nil {
t.Errorf("test #%d: Failed reading body: %v", i, err)
continue
@@ -103,6 +102,18 @@ func TestDateParsing(t *testing.T) {
"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{
@@ -244,6 +255,33 @@ func TestDateParsingCFWS(t *testing.T) {
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{
@@ -842,7 +880,7 @@ func TestAddressParser(t *testing.T) {
ap := AddressParser{WordDecoder: &mime.WordDecoder{
CharsetReader: func(charset string, input io.Reader) (io.Reader, error) {
- in, err := ioutil.ReadAll(input)
+ in, err := io.ReadAll(input)
if err != nil {
return nil, err
}