runtime icon indicating copy to clipboard operation
runtime copied to clipboard

UriBuilder creates Uri with wrong scheme if scheme has only one letter

Open Blackclaws opened this issue 3 years ago • 4 comments

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

Blackclaws avatar Aug 05 '22 12:08 Blackclaws

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:

area-System.Net

Milestone: -

msftbot[bot] avatar Aug 05 '22 12:08 msftbot[bot]

This might be related: https://github.com/dotnet/runtime/issues/59099

Blackclaws avatar Aug 05 '22 12:08 Blackclaws

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)?

MihaZupan avatar Aug 05 '22 15:08 MihaZupan

This issue has been marked needs-author-action and may be missing some important information.

msftbot[bot] avatar Aug 07 '22 22:08 msftbot[bot]

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!

karelz avatar Aug 09 '22 16:08 karelz