-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
dotnet/dotnet-api-docs
#12299Labels
area-System.NetdocumentationDocumentation bug or enhancement, does not impact product or test codeDocumentation bug or enhancement, does not impact product or test code
Milestone
Description
MailAddress is inconsistent in how it handles special characters in the display name portion of an address. Try the following code on any version of .NET, including .NET5:
using System;
using System.Net.Mail;
namespace MailAddressTest
{
class Program
{
static void Main(string[] args)
{
// display name accepts a name with \
var ok = new MailAddress("foo@foo.com", "Foo \\ Bar");
try
{
// however, the generated address fails to round-trip
var fail1 = new MailAddress(ok.ToString());
}
catch (FormatException e)
{
Console.WriteLine($"Fail1: {e.Message}");
}
try
{
// parsing an address from a string also fails for the same reason
var fail2 = new MailAddress("\"Foo \\ Bar\" <foo@foo.com>");
}
catch (FormatException e)
{
Console.WriteLine($"Fail2: {e.Message}");
}
}
}
}
I think the expectation is that round-tripping the mail address should always work, so the MaillAddress constructor that accepts separate display name and address parameters should perform the same parsing checks on the display name as the single-parameter constructor.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.NetdocumentationDocumentation bug or enhancement, does not impact product or test codeDocumentation bug or enhancement, does not impact product or test code