Description
The System.UriBuilder class cannot be used to build a mailto URI.
Reproduction Steps
The following code
var builder = new UriBuilder
{
Scheme = Uri.UriSchemeMailto,
UserName = "someone",
Host = "example.com",
Query = "subject=Testing",
Path = string.Empty,
};
Console.WriteLine(builder.ToString());
produces a URI value of
mailto:someone@example.com/?subject=Testing
which is not a valid mailto URI.
Expected behavior
A valid URI would be
mailto:someone@example.com?subject=Testing
There should not be a '/' character.
Actual behavior
The Path setter sets the value to '/' when the value is the empty string.
[AllowNull]
public string Path
{
get => _path;
set
{
_path = string.IsNullOrEmpty(value)
? "/"
: Uri.InternalEscapeString(value.Replace('\\', '/'));
_changed = true;
}
}
This makes sense for HTTP/S but makes the class unusable for mailto.
Regression?
No response
Known Workarounds
No response
Configuration
.Net 7.0.203
Windows 11 x64
Other information
No response
Description
The
System.UriBuilderclass cannot be used to build a mailto URI.Reproduction Steps
The following code
produces a URI value of
which is not a valid
mailtoURI.Expected behavior
A valid URI would be
There should not be a '/' character.
Actual behavior
The
Pathsetter sets the value to '/' when the value is the empty string.This makes sense for HTTP/S but makes the class unusable for mailto.
Regression?
No response
Known Workarounds
No response
Configuration
.Net 7.0.203
Windows 11 x64
Other information
No response