Skip to content

Commit 5c4db26

Browse files
committed
Improved address parser to handle unbalanced ')' (rfc7103)
1 parent a79e961 commit 5c4db26

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

MimeKit/Utils/ByteExtensions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ static ByteExtensions ()
145145
// Note: Allow '[' and ']' in the display-name of a mailbox address
146146
table['['] |= CharType.IsPhraseAtom;
147147
table[']'] |= CharType.IsPhraseAtom;
148+
149+
// Note: Allow ')' in the display-name of a mailbox address for rfc7103 unbalanced parens
150+
table[')'] |= CharType.IsPhraseAtom;
148151
}
149152

150153
//public static bool IsAscii (this byte c)

UnitTests/InternetAddressListTests.cs

+25
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,31 @@ public void TestParseErrantComma ()
900900
AssertParseAndTryParse (text, encoded, expected);
901901
}
902902

903+
[Test]
904+
[Ignore ("Address parser consumes the entire string as an unterminated comment")]
905+
public void TestParseMailboxWithUnbalancedOpenParenthesis ()
906+
{
907+
const string text = "(Testing <[email protected]>";
908+
const string encoded = "Testing <[email protected]>";
909+
var expected = new InternetAddressList {
910+
new MailboxAddress ("Testing", "[email protected]")
911+
};
912+
913+
AssertParseAndTryParse (text, encoded, expected);
914+
}
915+
916+
[Test]
917+
public void TestParseMailboxWithUnbalancedClosedParenthesis ()
918+
{
919+
const string text = "Testing) <[email protected]>";
920+
const string encoded = "\"Testing)\" <[email protected]>";
921+
var expected = new InternetAddressList {
922+
new MailboxAddress ("Testing)", "[email protected]")
923+
};
924+
925+
AssertParseAndTryParse (text, encoded, expected);
926+
}
927+
903928
[Test]
904929
public void TestParseMailboxWithUnbalancedQuotes ()
905930
{

0 commit comments

Comments
 (0)