Bug 4793 - UriTemplate.Match doesn't match for Uri's with escaped characters
Summary: UriTemplate.Match doesn't match for Uri's with escaped characters
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-05-01 07:55 UTC by David Ferguson
Modified: 2012-05-03 03:13 UTC (History)
1 user (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 David Ferguson 2012-05-01 07:55:02 UTC
In some cases, UriTemplate.Match fails to match when the Uri has escaped data in it.  In this case, one of the Uri segments had an escaped '?' in it.  The following is a unit test that reproduces the problem.

        [Test]
        public void EscapedUriCandidate ()
        {
            var candidateUri = new Uri (@"https://somehost:12345/path1/path2/path3/endprefix/tpath1/guid1/tpath2/~|~~|~%3F~|~Path{guid2}~|~/tpath3");
            var matchUri = new Uri (candidateUri.Scheme + "://" + candidateUri.Host + ":" + candidateUri.Port + @"/path1/path2/path3/endprefix");
            
            var template = new UriTemplate (@"tpath1/{guid}/tpath2/{encodedGuidString}/tpath3");
            var match = template.Match (matchUri, candidateUri);

            Assert.IsNotNull (match);
            Assert.That (match.BoundVariables ["GUID"] == "guid1");
            Assert.That (match.BoundVariables ["ENCODEDGUIDSTRING"] == "~|~~|~?~|~Path{guid2}~|~");
        }

This test passes successfully on Windows (.NET 4.0).  It fails with Mono.

I've modified my own fork with a potential fix and will issue a pull request.