Bug 29864 - public Uri(Uri baseUri, Uri relativeUri) strips . from path
Summary: public Uri(Uri baseUri, Uri relativeUri) strips . from path
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.12.0
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
Depends on:
Reported: 2015-05-07 17:52 UTC by Shawn
Modified: 2015-10-19 09:02 UTC (History)
4 users (show)

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


Description Shawn 2015-05-07 17:52:05 UTC
The public Uri(Uri baseUri, Uri relativeUri) method strips . characters in path incorrectly. 
Here is a simple unit test which should pass
public void DotInUrlTest()
    var uri = new Uri("https://blog.domain.com/en/images/topics/Misc./a.jpg", UriKind.Absolute);
    Assert.AreEqual("https://blog.domain.com/en/images/topics/Misc./a.jpg", uri.ToString());

    var baseUri = new Uri("https://blog.domain.com/", UriKind.Absolute);
    Assert.AreEqual("https://blog.domain.com/", baseUri.ToString());

    var reluri = new Uri("/en/images/topics/Misc./a.jpg", UriKind.Relative);
    Assert.AreEqual("/en/images/topics/Misc./a.jpg", reluri.ToString());

    //This test fails because the . is stripped out of /Misc./
    uri = new Uri(baseUri, reluri);
    Assert.AreEqual("https://blog.domain.com/en/images/topics/Misc./a.jpg", uri.ToString());

Test.DotInUrlTest :   Expected string length 52 but was 51. Strings differ at index 45.
  Expected: "https://blog.domain.com/en/images/topics/Misc./a.jpg"
  But was:  "https://blog.domain.com/en/images/topics/Misc/a.jpg"

Tested in 4.0 and 3.12.1 with same result
Comment 1 Jarrod 2015-05-13 13:54:51 UTC
Also seeing this issue, seems to be a regression.

The above unit test passes using mono 3.4.0 and 3.8.0
Comment 2 Jarrod 2015-05-14 15:44:28 UTC
Tested and fails in mono 3.10.0
Comment 3 Jarrod 2015-05-14 19:42:46 UTC
Stepped through the 3.12.1 source for the Uri class to see where this was happening.

Calling the Uri constructor:
public Uri (Uri baseUri, Uri relativeUri)

This constructor directly calls Merge

Down a ways inside the Merge function Reduce is call like this:
source += UriHelper.Reduce (path, true);

here true is passed as the second param which is called trimDots
internal static string Reduce (string path, bool trimDots)

When Reduce is going through the path segments one of the checks is makes is this:
if (segment == "." ||
    (trimDots && segment.EndsWith (".", StringComparison.Ordinal))) {
    segment = segment.TrimEnd ('.');

trimDots was passed as true, and this path segment as in the bug report above is "Misc." so the trailing dot in that segment is removed.

I am not sure what the intent of this code is but removing that trailing dot is incorrect for http urls at least.
Comment 4 marcos.henrich 2015-10-15 10:14:01 UTC
Hi Shawn, Jarrod,

Thank you for the bug report.

After some experiments on .NET I noticed that before .NET 4.5 dots were trimmed from the end of uri path segments.

In .NET 4.5 IRI parsing is enabled by default and dot are no longer
trimmed from the end of path segments.

Here is the pull request with the fix and test:
Comment 5 marcos.henrich 2015-10-19 09:02:47 UTC
Fixed in master a1d39d9b02ea634f8ba27b1df262f8047b07f363.

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

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.

Note You need to log in before you can comment on or make changes to this bug.