fxa / uritemplate-js

An javascript implementation of RFC6570 Uri Templates
MIT License
97 stars 20 forks source link

Percent encoding of variable names is required #6

Closed gavacho closed 11 years ago

gavacho commented 11 years ago

I apologize for not knowing how this behavior is defined by the RFC.

Given a template like: {&sort%5B%5D*}, the object which is passed to UriTemplate's expand method must also have its properties percent-encoded. It seems like percent-encoding should be the concern of UriTemplate and not the caller.

Here's a fiddle: http://jsfiddle.net/uqcMf/ - notice that the "filter" variable isn't expanded correctly.

gavacho commented 11 years ago

I don't mind opening a PR for this if someone can confirm it's a bug.

fxa commented 11 years ago

I see your point. But the RFC is a little inconsequent with encoding. See http://tools.ietf.org/html/rfc6570#section-2.3 "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. A varname containing pct-encoded characters is not the same variable as a varname with those same characters decoded. Applications that provide URI Templates are expected to be consistent in their use of pct-encoding within variable names." So I think, it is not a bug, but a ... RFC