geraintluff / uri-templates

JavaScript utility for RFC 6570: URI Templates
138 stars 21 forks source link

Make query expression optional in de-substitution #12

Closed gr0uch closed 9 years ago

gr0uch commented 9 years ago

When I have a template that looks like this:

{/type,ids,field}{?query*}

And I try to match it against a URI without the ? symbol:

/user/1,2,3/posts

It explodes and I just get an empty object {}. But when I add the ? symbol to the end of the URI, it works (matches type, ids, field). The caveat to appending the ? is that now I get {'': ''} in the query object that is extraneous so I delete it.

In substitution, if I pass in nothing as query, this works, but somehow it's not optional in de-substitution.

geraintluff commented 9 years ago

Good point, that is unintuitive. I'll have a look at a fix.

gr0uch commented 9 years ago

:+1: :beers: