damnhandy / Handy-URI-Templates

A Java URI Template processor implementing RFC6570

Home Page:https://damnhandy.github.io/Handy-URI-Templates/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relaxing variable name valid characters

osvaldopina opened this issue · comments

Hi,

I was looking at template uri spec (rfc 6570) and I saw that the specification for variable name is:

   variable-list  =  varspec *( "," varspec )
   varspec        =  varname [ modifier-level4 ]
   varname        =  varchar *( ["."] varchar )
   varchar        =  ALPHA / DIGIT / "_" / pct-encoded

but the spec for uri (rfc 3986) states that the valid queries are formed by:

   query         = *( pchar / "/" / "?" )
   pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
   unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
   reserved      = gen-delims / sub-delims
   gen-delims    = ":" / "/" / "?" / "#" / "[" / "]" / "@"
   sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                           / "*" / "+" / "," / ";" / "="

So, the folloing template {?var-name} is invalid but the expanded query ?var-name=var-value is valid.

What do you think about creating an option for relaxing template variable names to allow all valid uri query characters?

I'd rather not do this as it would break compatibility with other URI template processors. Keep in mind that a URI template is not a valid URI. It's a template. The - is a reserved character and could be used in a future version of the spec, so it's not unreasonable that it could be used again. In which case, relaxing it would break compatibility. It had been used in earlier versions of the spec. Yes, it is annoying that you can't have variable names with a - in it. There is a test negative test case that asserts this.

I've been re-thinking this as I've run into similar issues in my own work. It had me wondering about adding a non-strict mode, which could relax a few cases where the spec goes a bit too far.

@damnhandy, Would you still be willing to accept the creation of the non-strict mode?