Skip to content

Commit

Permalink
net/mail: fixed quoted-local
Browse files Browse the repository at this point in the history
Fixes some minor issues regarding quoted-string when parsing
the local-part.

Those strings should return an error:
- quoted-string without any content: `""@test.com`
- quoted-string containing tab: "\"\t\"@test.com"

Fixes golang#11293

Change-Id: Ied93eb6831915c9b1f8e727cea14168af21f8d3b
Reviewed-on: https://go-review.googlesource.com/12905
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
DenBeke authored and rsc committed Jul 31, 2015
1 parent 782eea0 commit bd1efd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/net/mail/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ Loop:
}
qsb = append(qsb, p.s[i+1])
i += 2
case isQtext(c), c == ' ' || c == '\t':
case isQtext(c), c == ' ':
// qtext (printable US-ASCII excluding " and \), or
// FWS (almost; we're ignoring CRLF)
qsb = append(qsb, c)
Expand All @@ -429,6 +429,9 @@ Loop:
}
}
p.s = p.s[i+1:]
if len(qsb) == 0 {
return "", errors.New("mail: empty quoted-string")
}
return string(qsb), nil
}

Expand Down
3 changes: 3 additions & 0 deletions src/net/mail/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ func TestAddressParsingAndFormatting(t *testing.T) {
`<".john.doe"@example.com>`,
`<"."@example.com>`,
`<".."@example.com>`,
`<"0:"@0>`,
}

for _, test := range tests {
Expand Down Expand Up @@ -563,6 +564,8 @@ func TestAddressParsingAndFormatting(t *testing.T) {
`<test@.>`,
`< @example.com>`,
`<""test""blah""@example.com>`,
`<""@0>`,
"<\"\t0\"@0>",
}

for _, test := range badTests {
Expand Down

0 comments on commit bd1efd5

Please sign in to comment.