Bug 29941 - Uri.TryCreate deviates from .NET reference implementation for relative links
Summary: Uri.TryCreate deviates from .NET reference implementation for relative links
Status: RESOLVED FEATURE
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2015-05-11 10:37 UTC by SN
Modified: 2015-08-29 07:52 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description SN 2015-05-11 10:37:03 UTC
Consider this F# snippet.
------ bug.fsx begins -------
open System

let _ =
    match Uri.TryCreate("/foo/bar.js", UriKind.RelativeOrAbsolute) with
    | true, v -> printfn "as string=%A, IsAbsoluteUri=%b" v v.IsAbsoluteUri
    | _ -> printfn "returned false"
------- bug.fsx ends -------

On mono 3.2.8 it returns
as string=file:///foo/bar.js, IsAbsoluteUri=true

But under .NET the same script returns
as string=/foo/bar.js, IsAbsoluteUri=false
Comment 1 SN 2015-05-11 14:01:25 UTC
Also, if the 1st param to Uri.TryCreate is "http:" then the result will be different in .NET (return val is true) and mono (return val is false), regardless of UriKind.
This came up while I was testing various corner cases.
Comment 2 SN 2015-05-12 17:58:50 UTC
Another interesting find today:
Uri.TryCreate("//www.aaa.com/z.png", UriKind.Relative)

produces //www.aaa.com/z.png on .NET and
          /www.aaa.com/z.png on mono.
I was careful not to pass strings via the cmd line which could subject them to interpretation by the CMD/powershell prompt or unix shell.
The return values match but the ToString() representation is significantly different.
Comment 3 marcos.henrich 2015-08-29 07:52:47 UTC
There is a doc explaining why the UriKind.RelativeOrAbsolute cannot be fixed along with a workaround.

http://www.mono-project.com/docs/faq/known-issues/urikind-relativeorabsolute/

The second problem you mentioned looks too much of an edge case to be fixed. But if it causes you any problem on a real case, let me know and I will fix it.

The third problem cannot be fixed for the same reason as the first one, Mono assumes the given input is an absolute path and ignores repeated file separators.