tavis-software / Tavis.UriTemplates

.Net implementation of the URI Template Spec https://tools.ietf.org/html/rfc6570
Apache License 2.0
169 stars 39 forks source link

Malformed template error when query-string param names have hyphens #56

Closed BryanWilhite closed 1 year ago

BryanWilhite commented 6 years ago

The following will throw a Malformed template error:

var apiBase = "https://azure.search.windows.net/";
var apiPath = "{componentName}/{itemName}{?api-version}";
var template = new UriTemplate(string.Concat(apiBase, apiPath));
template.GetParameterNames();

This will work fine:

var apiBase = "https://azure.search.windows.net/";
var apiPath = "{componentName}/{itemName}{?api_version}";
var template = new UriTemplate(string.Concat(apiBase, apiPath));
template.GetParameterNames();

Is the use of a hyphen in api-version a violation of URI Template Spec RFC6570?

Interestingly, this will work: {?api%2Dversion} but not convert to -.

baywet commented 1 year ago

According to the RFC 6570 section 2.3 on var names only the following characters are allowed in the variable name:

And then proceeds to define

A varname MAY contain one or more pct-encoded triplets. These triplets are considered an essential part of the variable name and are not decoded during processing

So the current behavior you're describing follows the specification.

Closing since this is an old issue.