Runtime: Constructor of `Uri` class does not throw `UriFormatException` for relative uri (core 2.1.5)

Created on 5 Nov 2018  路  4Comments  路  Source: dotnet/runtime

According to document, the constructor of Uri class should throw UriFormatException given the following inputs:

new Uri("/relative");

or

new Uri("/relative", UriKind.Absolute);

However, it will not throw any exceptions at least under Linux and Mac OS. It automatically adds "file:\" prefix on it.

area-System.Net documentation

Most helpful comment

However, it will not throw any exceptions at least under Linux and Mac OS.

/relative is a valid absolute path on Unix.

All 4 comments

I confirm right exception throw on Windows in both cases

System.UriFormatException: Invalid URI: The format of the URI could not be determined.

Seems expected https://github.com/dotnet/corefx/blob/0bfc4f3cf62f6fc29162ad5b1b89acc14124a375/src/System.Private.Uri/src/System/Uri.cs#L3664

/cc @karelz @rmkerr

However, it will not throw any exceptions at least under Linux and Mac OS.

/relative is a valid absolute path on Unix.

Correct, Uri is weird and historically works also for file paths - that's why the example is interpreted as Unix absolute path.

The documentation you linked does not say anything about accepting file paths. Maybe it is something we could improve in the docs - thoughts @rmkerr?

Yeah, I can update the documentation for URI to describe our support for implicit file paths.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iCodeWebApps picture iCodeWebApps  路  3Comments

omajid picture omajid  路  3Comments

noahfalk picture noahfalk  路  3Comments

GitAntoinee picture GitAntoinee  路  3Comments

matty-hall picture matty-hall  路  3Comments