This project has moved. For the latest updates, please go here.
1

Closed

meta characters are not replaced as intended

description

Try this test:
        UriPattern p = UriPattern.Create("/LiveContacts/Contacts/Contact({ContactId})");
        IDictionary<string, string> values = p.Parse("/LiveContacts/Contacts/Contact(1001)");
        Assert.AreEqual<string>("1001", values["ContactId"]);
 
It will fail because in the UriPattern.BuildRegex the code is supposed to be doing a regex replace to escape all meta characters, but it actually just attempts a string replace, which does nothing.
 
The following lines fix the problem.
 
private static Regex regexMetaPattern = new Regex(@"[\[]()\&\^\$\?#+*\|>\<]", RegexOptions.Compiled); // This is a regex not a string
private static string regexMetaCharactersReplacements = @"\$0"; // Removed a slash here also
 
In UriTemplate.BuildRegex, change the template.Replace(...) to
template = regexMetaPattern.Replace(template,regexMetaCharactersReplacements) + ".*";
 
I looked at Snell's original code and the bug is there also.
Closed Oct 26, 2007 at 5:58 AM by IDisposable

comments

IDisposable wrote Oct 26, 2007 at 5:46 AM

Good catch... I once looked at that code and thought... no idea why it was being done, but my patterns never had things like your pattern. I've integrated you fix and will push a release tomorrow.

wrote Oct 26, 2007 at 5:56 AM

wrote Oct 26, 2007 at 5:56 AM

Resolved with changeset 12957.

IDisposable wrote Oct 26, 2007 at 5:58 AM

** Closed by IDisposable 10/25/2007 9:56 PM

IDisposable wrote Oct 26, 2007 at 5:58 AM

wrote Oct 26, 2007 at 5:58 AM

wrote Oct 26, 2007 at 5:58 AM

IDisposable wrote Oct 27, 2007 at 2:10 AM

To be fair, it was my mistake in translating from the java original, since in java's string class, the replaceAll method expects a regex pattern, not a raw pattern. Mea Culpa

wrote Feb 12, 2013 at 8:51 PM

wrote May 14, 2013 at 7:36 AM