@@ -847,6 +847,35 @@ public void TestParseMailboxWithEscapedAtSymbol (RfcComplianceMode compliance, b
847847 }
848848 }
849849
850+ [ Test ]
851+ public void TestInternalTryParseRecoveryForBadSyntax ( )
852+ {
853+ string text = "\" Winnie Cooper\" <wcooper@wonder-years.com>, \" Last Name, First Name\" (oops, no address), \" Kevin Arnold\" <kevin@wonder-years.com>" ;
854+ var options = ParserOptions . Default . Clone ( ) ;
855+ var rawValue = Encoding . UTF8 . GetBytes ( text ) ;
856+ int length = rawValue . Length ;
857+ MailboxAddress mailbox ;
858+ int index = 0 ;
859+
860+ options . AddressParserComplianceMode = RfcComplianceMode . Strict ;
861+ options . AllowUnquotedCommasInAddresses = false ;
862+ options . AllowAddressesWithoutDomain = false ;
863+
864+ InternetAddressList . TryParse ( AddressParserFlags . InternalTryParse , options , rawValue , ref index , length , false , 0 , out var parsed ) ;
865+
866+ Assert . That ( parsed , Has . Count . EqualTo ( 2 ) , "Expected 2 addresses to be parsed." ) ;
867+ Assert . That ( parsed [ 0 ] , Is . InstanceOf < MailboxAddress > ( ) , "First address should be a MailboxAddress." ) ;
868+
869+ mailbox = ( MailboxAddress ) parsed [ 0 ] ;
870+ Assert . That ( mailbox . Name , Is . EqualTo ( "Winnie Cooper" ) , "First address name does not match." ) ;
871+ Assert . That ( mailbox . Address , Is . EqualTo ( "wcooper@wonder-years.com" ) , "First address does not match." ) ;
872+ Assert . That ( parsed [ 1 ] , Is . InstanceOf < MailboxAddress > ( ) , "Second address should be a MailboxAddress." ) ;
873+
874+ mailbox = ( MailboxAddress ) parsed [ 1 ] ;
875+ Assert . That ( mailbox . Name , Is . EqualTo ( "Kevin Arnold" ) , "Second address name does not match." ) ;
876+ Assert . That ( mailbox . Address , Is . EqualTo ( "kevin@wonder-years.com" ) , "Second address does not match." ) ;
877+ }
878+
850879 #region Rfc7103
851880
852881 // TODO: test both Strict and Loose RfcCompliance modes
0 commit comments