-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
Constructing a URI with the UriBuilder class should produce valid URIs when setting valid UserName and/or Password properties. Instead, an UriFormatException is thrown if the user name or password contains a character that should be percent-encoded.
It should be the responsibility of the UriBuilder to properly percent-encode characters in the UserName and/or Password properties. Note that the documentation of the properties does not mention anything about percent-escaping so by the principle of least astonishment I'd expect the UriBuilder to properly escape what needs to be escaped.
Reproduction Steps
Run the following code:
var builder = new UriBuilder("https://www.microsoft.com")
{
UserName = "mallory@hackers.net",
Password = "hunter2",
};
Console.WriteLine(builder.Uri);Expected behavior
The following URI is written to the console.
https://mallory%40hackers.net:hunter2@www.microsoft.com/
Actual behavior
An UriFormatException is thrown with the following message.
Invalid URI: Invalid port specified.
Regression?
I don't know whether this is a regression or not.
Known Workarounds
Manually percent-escaping the UserName and Password but that should not be necessary.
Configuration
Version of .NET: .NET 6.0.8
OS: All
Architecture: All
Other information
No response