Created
April 20, 2014 18:16
-
-
Save sharwell/11120994 to your computer and use it in GitHub Desktop.
Reversing an RFC 6570 URI Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^(?<part0>/v2/)(?<part1>(?:(?:(?:(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)|(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)(?:,(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*))*?|(?:(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*),(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*))(?:,(?:(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*),(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)))*?)))?)(?<part2>/servers)(?<part3>(?:\?(?:(?:(?:(?:changes%2Dsince)=(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)|(?:changes%2Dsince)=(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)(?:,(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*))*?|(?:changes%2Dsince)=(?:(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*),(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*))(?:,(?:(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*),(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)))*?)|(?:(?:image)=(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)|(?:image)=(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA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fA-F0-9]{2})))*)|(?:host)=(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)(?:,(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*))*?|(?:host)=(?:(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*),(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*))(?:,(?:(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*),(?:(?:(?:[a-zA-Z0-9._~-]|(?:%[a-fA-F0-9]{2})))*)))*?)))*))?)$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Testing.Rfc6570 | |
{ | |
using System; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using Rackspace.Net; | |
[TestClass] | |
public class SampleTest | |
{ | |
[TestMethod] | |
public void TestComplicatedExpressions() | |
{ | |
string template = "/v2/{tenant_id}/servers{?changes%2Dsince,image,flavor,name,marker,limit,status,host}"; | |
UriTemplate uriTemplate = new UriTemplate(template); | |
Uri uri = new Uri("/v2/855564/servers?image=3&name=Foo&flavor=1", UriKind.Relative); | |
UriTemplateMatch match = uriTemplate.Match(uri); | |
Assert.IsNotNull(match); | |
Assert.AreEqual("3", match.Bindings["image"].Value); | |
Assert.AreEqual("Foo", match.Bindings["name"].Value); | |
Assert.AreEqual("1", match.Bindings["flavor"].Value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This test passes with the latest code in my working branch. The interesting part is how complicated the regular expression is which is generated internally to support matching a candidate URI to the URI Template (click the View Raw button to see the full text).