Bug 5921 - Uri.MakeRelativeUri failed on directories
Summary: Uri.MakeRelativeUri failed on directories
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-06-29 06:08 UTC by serguei_t
Modified: 2015-10-13 11:03 UTC (History)
3 users (show)

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:

Description serguei_t 2012-06-29 06:08:48 UTC
Method Uri.MakeRelativeUri(uri) return N-1 dir-ups "../" instead of N.

Uri uri1 = new Uri("file:///dir/file.txt");
Uri uri2 = new Uri("file:///dir/subdir/");
Assert.AreEqual("../file.txt", uri2.MakeRelativeUri(uri1).ToString());
// Expected: "../file.txt" But was: "file.txt"		

Uri uri3 = new Uri("file:///dir/file.txt");
Uri uri4 = new Uri("file:///dir/subdir/subsubdir/");
Assert.AreEqual("../../test.txt", uri4.MakeRelativeUri(uri3).ToString());
// Expected: "../../file.txt" But was: "../file.txt"		

// But it works if you add a "dummy" file name
Uri uri5 = new Uri("file:///dir/file.txt");
Uri uri6 = new Uri("file:///dir/subdir/subsubdir/dummy");
Assert.AreEqual("../../test.txt", uri6.MakeRelativeUri(uri5).ToString());
Comment 1 serguei_t 2012-06-29 06:22:04 UTC
I found also a bug with port number

Uri uri1 = new Uri("http://www.contoso.com:8000/");
Uri uri2 = new Uri("http://www.contoso.com/test/test.htm");
Assert.AreEqual("http://www.contoso.com/test/test.htm", uri2.MakeRelativeUri(uri1).ToString());
// Expected: "http://www.contoso.com/test/test.htm" But was: "../"
Comment 2 Antonius Riha 2012-10-04 00:26:26 UTC
The bug reported in the original description is fixed in master: https://github.com/mono/mono/commit/ddd262a40db4aa92e3938ad6da160194d1da1c5a

I've no idea regarding the port number bug, though.