Skip to content

net/mail: prevent whitespace in domain part of addr-spec #74920

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/net/mail/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (p *addrParser) consumeAddrSpec() (spec string, err error) {

// domain = dot-atom / domain-literal
var domain string
p.skipSpace()

if p.empty() {
return "", errors.New("mail: no domain in addr-spec")
}
Expand Down
30 changes: 30 additions & 0 deletions src/net/mail/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,36 @@ func TestAddressParsing(t *testing.T) {
Address: "jdoe@[192.168.0.1]",
}},
},
// No whitespace allowed in domain
{
`[email protected]`, // should pass
// `jdoe@ machine.example`, // should fail
[]*Address{{
Address: "[email protected]",
}},
},
{
`John Doe <[email protected]>`, // should pass
// `John Doe <jdoe@ machine.example>`, // should fail
[]*Address{{
Name: "John Doe",
Address: "[email protected]",
}},
},
{
` , [email protected],,John <[email protected]>,,`, // should pass
// ` , [email protected],,John <jdoe@ one.test>,,`, // should fail
[]*Address{
{
Name: "",
Address: "[email protected]",
},
{
Name: "John",
Address: "[email protected]",
},
},
},
}
for _, test := range tests {
if len(test.exp) == 1 {
Expand Down