UriBuilder creates Uri with wrong scheme if scheme has only one letter
Description
When using UriBuilder it is possible to get a Uri with the wrong scheme if the scheme has only a single letter.
This is similar to the issue that the Uri class itself does not parse "a://hostname:3456" correctly.
Reproduction Steps
var uriBuilder = new UriBuilder();
uriBuilder.Scheme = "a";
uriBuilder.Host = "hostname";
uriBuilder.Port = 3456;
Console.WriteLine(uriBuilder.Uri);
This writes "file:///a://hostname:3456/" even though the Scheme was set to "a"
Expected behavior
This should write: "a://hostname:3456"
Actual behavior
Writes "file:///a://hostname:3456/"
Regression?
No response
Known Workarounds
No response
Configuration
.Net Runtime 6.0.301
Other information
No response
Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.
Issue Details
Description
When using UriBuilder it is possible to get a Uri with the wrong scheme if the scheme has only a single letter.
This is similar to the issue that the Uri class itself does not parse "a://hostname:3456" correctly.
Reproduction Steps
var uriBuilder = new UriBuilder();
uriBuilder.Scheme = "a";
uriBuilder.Host = "hostname";
uriBuilder.Port = 3456;
Console.WriteLine(uriBuilder.Uri);
This writes "file:///a://hostname:3456/" even though the Scheme was set to "a"
Expected behavior
This should write: "a://hostname:3456"
Actual behavior
Writes "file:///a://hostname:3456/"
Regression?
No response
Known Workarounds
No response
Configuration
.Net Runtime 6.0.301
Other information
No response
| Author: | Blackclaws |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
This might be related: https://github.com/dotnet/runtime/issues/59099
Uri unfortunately attempts to recognize implicit file paths. As a result, single-letter schemes may be interpreted as file Uris.
You are correct in that #59099 is related - with the AllowImplicitFilePaths flag set to false, this would instead be recognized as an absolute Uri with scheme a.
What is the significance of using Uris like this in your scenario (as opposed to any other more descriptive scheme)?
This issue has been marked needs-author-action and may be missing some important information.
Triage: We do not see good use case for single-letter schema in Uri. Given implementation details it would be difficult to change and overlaps with file paths. Closing as Won't Fix. Let us know if we missed some angle, thanks!