ioseb/uri-template

URL encoding issue

Closed this issue · 4 comments

The URI template parser has logic built in that will tries to not double URL encode values. This can cause issues if you actually wish for a URL to literally contain "%20". This should be encoded into "%2520".

For example: http://www.foo.com/baz bar%20
Should become: http://www.foo.com/baz%20bar%2520
But instead is currently: http://www.foo.com/baz%20bar%20

Hi, thanks for letting me know! I'll look into it asap.

I looked into the old issue we fixed already several months ago and it looks similar.

i believe it's not a bug but right behaviour. Spec says:

If the literal character is allowed anywhere in the URI syntax
(unreserved / reserved / pct-encoded ), then it is copied directly to
the result string. Otherwise, the pct-encoded equivalent of the
literal character is copied to the result string by first encoding
the character as its sequence of octets in UTF-8 and then encoding
each such octet as a pct-encoded triplet.

And here are ABNF definitions of ( unreserved / reserved / pct-encoded ):

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

Is not it correct?

Hm. Ok. Thanks for the information. It's pretty difficult to use URL encoding of user supplied data with this implementation, but I'll see what I can do.

Np. Just to be clear, if it's a bug i'd be rather happy to fix it asap(maybe i'm missing something in spec).