Bug 8981 - The System.Uri class does not use the UriParser infrastructure
Summary: The System.Uri class does not use the UriParser infrastructure
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2012-12-17 07:22 UTC by Alan McGovern
Modified: 2014-08-07 04:35 UTC (History)
3 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 FIXED

Description Alan McGovern 2012-12-17 07:22:19 UTC
.NET 2 introduced a 'UriParser' [0] class which is used by System.Uri to parse strings into Uri objects. Our current implementation of System.Uri completely ignores this infrastructure and does all the parsing inside the Uri class itself. As such, it is impossible to define custom Uri schemes and have them parsed successfully.

Our System.IO.Packaging API requires this support to function correctly. We've been limping along for the last few years with some hacks internally to allow very very basic PackUri support, but we have dozens of failing tests [1] which need fixing. I believe the PackUriParser I implemented  will work once System.Uri uses the UriParser infrastructure, but it might need some tweaking too.

[0] http://msdn.microsoft.com/en-us/library/system.uriparser.aspx
[1] https://github.com/mono/mono/blob/master/mcs/class/WindowsBase/Test/System.IO.Packaging/PackUriHelperTests.cs
Comment 1 Miguel de Icaza [MSFT] 2012-12-17 17:53:53 UTC
We should explore the UriParser implementation.

We recently rewrote the Uri class to drop its dependency on Regex, since that brings the world on mobile devices.   We should not regress when we go down the UriParser path.
Comment 2 Martin Baulig 2012-12-17 19:59:06 UTC
If I remember correctly, there's a lot more brokenness in the Uri class, for instance we don't support the new unicode domain names that were introduced by MS in .NET 4.0 and I also think we don't always properly escape things.

Which means that class needs some love and using UriParser may be a good idea.

However, I'm not sure about that Regex problem that Miguel mentioned.
Comment 3 Miguel de Icaza [MSFT] 2012-12-17 20:05:55 UTC
Martin,

I can explain.

Our version of Uri used to use a System.Text.RegularExpressions.Regex to parse a URI, which was probably very easy for a first implementation but had the downside of being difficult to extend but most importantly, it meant that even using "Uri" for a simple task would bring Regex and all of its depending classes.   For mobile applications that was a lot of code.

So we rewrote it a few months ago to have a pure parser that does not depend on Regex.

If we decide to move to UriParser, we should make sure that UriParser does not use Regex either to shortcut things.
Comment 4 Alan McGovern 2012-12-18 05:14:32 UTC
I would assume most of the work will be stripping the code out of Uri.cs and putting it in the various UriParser subclasses which are in the BCL. These are the subclasses in the BCL:

    System.FileStyleUriParser
    System.FtpStyleUriParser
    System.GenericUriParser
    System.GopherStyleUriParser
    System.HttpStyleUriParser
    System.LdapStyleUriParser
    System.NetPipeStyleUriParser
    System.NetTcpStyleUriParser
    System.NewsStyleUriParser

We have tests for at least some of these subclasses and some of those tests are marked as [Category ("NotWorking")] too. Ideally those tests would need to be fixed and enabled as part of this.
Comment 5 Martin Baulig 2013-06-26 06:30:49 UTC
I tried to look into the IPv6-related problems of the Uri class - and well, it really needs a lot of love.

In addition to using the UriParser infrastructure, it should use use the parser for IsWellFormedOriginalString() and IsWellFormedUriString().
Comment 6 marcos.henrich 2014-07-29 03:08:13 UTC
Hi,

The following pull request adds correct use of registered scheme parser, which fixes most of the disabled tests.
https://github.com/mono/mono/pull/1168

The remaining disabled tests can be fixed by adding to PackUriHelper methods validation code that throws expected exceptions.

Once the pull request 1168 is accepted I will add the validation code and enable all the PackUriHelperTests tests.
Comment 7 marcos.henrich 2014-08-07 04:22:03 UTC
The pull request for this issue can be found in the link below.
https://github.com/mono/mono/pull/1199
Comment 8 marcos.henrich 2014-08-07 04:35:31 UTC
Fixed in master ed065cd04dbf3686033f6474946c40d49ad424b1.