mono/mono — pull request #1168 by esdrubal (2014-07-17 18:52:48+00:00)
Title: Iriparsing

**Major changes:**

Added property IriParsing to System/Uri.cs that switches between .NET 4.5 and .NET 4.0 default parsing behavior.
The property value can be initialized from the environment variable MONO_URI_IRIPARSING, and reflection can be used to change the field s_IriParsing.

Created System/UriHelper.cs with methods FormatAbsolute and FormatRelative used to escape, unescape characters, replace backslash, and reduce paths depending on scheme, UriComponent, UriFormat and some flags that can be provided.

Changed System/Uri.cs and System/UriParser.cs to use UriHelper.FormatAbsolute and UriHelper.FormatRelative.

Changed System/UriParseComponents.cs to handle IpV6 hosts, Unix/Windows paths.

Added Test/System/StringTester.cs that generates/saves or loads/asserts expected values.

Added Test/System/UriPermutationsTest.cs that generates or asserts the Uri methods and properties output for multiple combinations of scheme (http, https, ...), location (path, fragment, query), encoded and decoded characters (all ASCII, some Unicode), reduce paths.

Updated existing tests Test/System/UriTest.cs and Test/System/UriTest2.cs with the IriParsing behavior differences.

**To Do:**

Although the new IriParsing behavior is implemented and tests are passing, a code refactoring of some replicated code should be done.

The same kind of parsing logic was and is now even more replicated in 3 different places Uri.Merge, Uri.ParseNoException and UriParseComponents.ParseComponents.

The plan is to improve UriParseComponents.ParseComponents to check Uri validity and return errors, as well as data other than components as isUnc, isAbsoluteUri, scope_id. Then Uri.Merge and Uri.ParseNoException will be able to use UriParseComponents.ParseComponents allowing the removal of the replicated code from Uri.cs.

**Tests to fix:**

- UriBuilderTest.IPv6_Host
- UriPermutationsTest.PercentageEncoding_LocalPath
- UriPermutationsTest.Reduce_LocalPath
- UriTest.HexUnescapeMultiByte
- UriTest.Unescape