uritemplates icon indicating copy to clipboard operation
uritemplates copied to clipboard

hyphen ("-") in named path params is treated invalid

Open PankhudiB opened this issue 4 years ago • 1 comments

uritemplates.Parse() gives error if the path has hyphen in one of the path-param name.

Example : template, parseErr := uritemplates.Parse("https://api.github.com/repos/{repo-name}")

Gives error : not a valid name: repo-name

I am not able to comprehend why shouldn't this be allowed ? the regex used for validation is -----> "^([A-Za-z0-9_\.]|%[0-9A-Fa-f][0-9A-Fa-f])+$"

PankhudiB avatar Oct 20 '20 13:10 PankhudiB

I’m sorry I didn’t notice this earlier! The dash is not a valid character in variable names: https://tools.ietf.org/html/rfc6570#section-2.3

You can percent-encode it as %2D instead:

https://api.github.com/repos/{repo%2Dname}

jtacoma avatar Jan 04 '21 04:01 jtacoma