Skip to content

Commit

Permalink
fix(GODT-2637): Fix rfc5322 address list parsing with trailing sep.
Browse files Browse the repository at this point in the history
Fix parsing of addresses if there is no more input after the separator.
  • Loading branch information
LBeernaertProton committed May 16, 2023
1 parent d18e593 commit edc685b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rfc5322/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ func parseAddressList(p *Parser) ([]*mail.Address, error) {
if ok, err := tryParseCFWS(p.parser); err != nil {
return nil, err
} else if ok {
// Only continue if the next input is EOF or comma or we can run into issues with parsring
// Only continue if the next input is EOF or comma or we can run into issues with parsing
// the `',' address` rules.
if p.parser.Check(rfcparser.TokenTypeEOF) || p.parser.CheckWith(isSep) {
continue
}
}

// Check there is still input to be processed before continuing.
if p.parser.Check(rfcparser.TokenTypeEOF) {
break
}

// address
addr, consumedSemiColon, err := parseAddress(p)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions rfc5322/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,10 @@ func FuzzRFC5322(f *testing.F) {
_, _ = parseNameAddr(p)
})
}

func TestParse_AddressAngleAddrOnlyWithSeparator(t *testing.T) {
// EOF was not properly handled after separator.
addrList, err := ParseAddressList("<[email protected]>,")
assert.NoError(t, err)
require.Equal(t, addrList[0].Address, "[email protected]")
}

0 comments on commit edc685b

Please sign in to comment.